Apply Two Search Filters to Same DataTable

Apply Two Search Filters to Same DataTable

elite-robelite-rob Posts: 26Questions: 0Answers: 0
edited April 2012 in General
Hello All,

My developers and I are trying to accomplish something that my gut tells me would be possible to do... but we're a bit stuck.

Basically we have a 5 column table.
One of the columns is titled "Status" and it will always have one of five values.
We created a drop-down menu (that appears beside the column title) that let's the user choose to filter based on one of these statuses.
This actually works perfectly.

We also have the standard DataTables search box just above the table.
This also works perfectly.

The problem is that if we try to combine BOTH filters, then it doesn't work.

Only the last filter (either the search box at the top or the status drop-down menu) will actually take effect and the other filter is ignored.

What this means is that we cannot say something like "Show me all matching rows that have ABCDEFG and a status of DRAFT".

Is there any way to set this up so that it can properly accept and apply both filters?

As always, any insight is greatly appreciated!

I've included a copy of our code below for your reference.

[code]

var oTable;
var giCount = 5;

$(document).ready(function() {
oTable = $('#EmailStatus').dataTable({
"iDisplayLength": 25,
"sPaginationType": "full_numbers",
"aaSorting": [[0, 'desc']],
"aoColumns": [
null,
null,
{ "bSortable": false, "bSearchable": false },
{ "bSortable": false, "bSearchable": false },
{ "bSortable": false },
null
]

});
oTable.fnSetColumnVis(0, false);
});


function showFilteredEmails(a, b) {
var str = "";
var oTable = "";
var term = "";
$(document).ready(function() {
oTable = $('#EmailStatus').dataTable();


if (b == "all") { term = ""; } else { term = b; }

oTable.fnFilter(term, null, false, true, false);
oTable.fnDraw();
});

}



[/code]

[code]



Date
Name
Edit
Copy
Status


See all
Draft
Running
Sent
Scheduled
Incomplete



Sent On





*Row Data Inserted Here*




[/code]

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > oTable.fnFilter(term, null, false, true, false);

    If you are filtering here only on a single column, rather than putting in null for the second parameter, pass int he column number you want to filter on. DataTables does global filtering + column filtering on each column, so that should do what you want :-)

    Allan
  • elite-robelite-rob Posts: 26Questions: 0Answers: 0
    Thanks Allan.

    As always, you're the best!

    We'll give that a try.
This discussion has been closed.