jquery datatables server side update to filter out inactive records

Posted on 2013-01-08
Last Modified: 2013-01-10
I have the following jQuery datatables initialization code and on the page
pTable = $('#myTable').dataTable({
					"bProcessing": true,
					"bServerSide": true,
					"bStateSave": false,
					"bLengthChange": false

Open in new window

Additionally I have a checkbox on the page above myTable that allows a user to see only records with an “active” status.  
 Only active <input id="active" onClick="showActive(this)" type="checkbox" name="selected">							   

Open in new window

I’m not certain what dataTables API to use (if there is even one) to accomplish this.  Something like pTable.fnFilter(‘active’) but that keeps all the filtering and sorting already present in the table.  Is there a function to update the server side call but maintain the filtering and sorting?
Question by:HyperBPP
  • 2
  • 2

Accepted Solution

tjyoung earned 500 total points
ID: 38758355
yes that is doable, no problem. Might want to use 2 radio buttons. Show active, show all or something like that. I've attached a jpeg of one of my tables showing filters in use. Relevant code for my table radio button other then the jquery for theshown below:

"fnServerParams": function ( aoData ) {
            aoData.push( {"name": "calltype", "value": $('input:radio[name="calltype"]:checked').val()} )

You also need the fnReload linked up (check, not sure on the name, might be fnDraw?). That is called when you click the radio button and reloads the table.

//radio button code calling the fnDraw
$("input:radio[name='calltype']").click( function () {
    oTable.fnPageChange( 'first', false );
      } );

table sample

Author Comment

ID: 38764933
Works a charm!  Thanks!

Author Closing Comment

ID: 38764937
Thanks!  Works great!

Expert Comment

ID: 38765150
Sure glad to help

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question