Trouble Filtering Displayed Data

Trouble Filtering Displayed Data

jtoddjtodd Posts: 4Questions: 2Answers: 0

Hi There,

I am having trouble filtering the data displayed by DataTables using both the filter function on initComplete and the search/searchCols functions. I am including both of my attempts at filtering but only expect to use one in the final code.

            fulcrumDomainTable = $('#fulcrum-domain-table').DataTable({
                "processing": true,
                "paginate": false,
                "scrollY": "200px",
                "scrollCollapse": true,
                "dom": '<"top">rt<"bottom">',
                "filter": false,
                "ajax": {
                    "url": fulcrumDomainUrl,
                    "dataSrc": "fulcrumDomainStatuses"
                },
                "initComplete": function(){
                    this.DataTable().columns([1]).data().filter(function(v,i) {
                        return v === "D01";
                    });
                    $("#fulcrum-domain-table-footer").text("Request UUID " + uuid);
                    $("#fv-row-6").show();
                    fulcrumDomainTable.columns.adjust().draw();
                },
                "order": [[1,'asc']],
                "columnDefs": [
                               {"targets": "dateCol",
                                "render": function(value) {
                                    return formatDate(value);
                                    }
                               }
                               ],
                "search": {"search": "D01"},
                "columns": [
                    {"className": "details-control",
                    "orderable": false,
                    "data": null,
                    "defaultContent": ''},
                    {"data": "domain"},
                    {"data": "resultTypeCode"},
                    {"data": "transactionDate"}
                    ]
            });

Thanks!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947
    edited August 2017 Answer ✓

    "search": {"search": "D01"},

    This should work.

    filter() won't work. This is in the doc for filter():

    This method should not be confused with search() which is used to search for records in the DataTable - i.e. the filter method does not change the rows that are displayed in the DataTable.

    You could try something like this:

    initComplete: function(){
            this.DataTable().columns([1]).search("D01" ).draw();
            }
    

    If neither works for you then we probably need to see a non-working example with your data. I can build generic test cases to show either of these working.

    Kevin

  • jtoddjtodd Posts: 4Questions: 2Answers: 0

    Thanks!

    I tried:

    this.DataTable().columns([1]).search("D01" ).draw();

    But that also didn't work.

    Here is some data:

    Domain Result Type Code Tran Date
    D01 NO_DATA 2017-08-17T14:54:24Z
    D02 NO_DATA 2017-08-17T14:54:24Z
    D03 NO_DATA 2017-08-17T14:54:24Z

    Column 0 is detail-controls so Domain is in column 2.

    I agree search should work the way I have it, I also tried searchCols with no luck.

  • jtoddjtodd Posts: 4Questions: 2Answers: 0

    I got it!

    I took out:

    "filter": false,

    then

    "search": {"search": "D01"},

    works perfectly.

This discussion has been closed.