Filter table in Editor instance

Filter table in Editor instance

BmokryBmokry Posts: 2Questions: 2Answers: 0

New to DataTables. Trying to get a simple column filter to work. Example code in the API .filter() explanation does not filter my table. Code developed using older DataTables terminology (commented out in code) that I found through internet search does filter it. What am I missing with the .filter()?

var table = $('#1728ReportEdit').DataTable( {
dom: 'Bfrtip',
ajax: "php/table.1728ReportEdit.php",

    columns: [
        {
            "data": "cnum"
        },
        {
            "data": "progcategory"
        },
        {
            "data": "purposeactivity"
        },
        {
            "data": "projecttitle"
        },
        {
            "data": "moneyraised"
        },
        {
            "data": "hourscount"
        },
        {
            "data": "date"
        },

    ],



    buttons: [
        {  extend: 'collection',
            text: 'Export',
            buttons: [
                'copy',
                'excel',
                'csv',
                'pdf',
                'print'
            ]
        },
        { extend: 'create', editor: editor },
        { extend: 'edit',   editor: editor },
        { extend: 'remove', editor: editor }
    ]


} 



);

// var filtercnum = '8285',
// filterIndex = 0;
//
//$.fn.dataTableExt.afnFiltering.push(
// function( oSettings, aData, iDataIndex ) {
// return aData[filterIndex].indexOf(filtercnum)>-1;
// }
//);

var filteredData = table
.column(0)
.data()
.filter( function ( value, index ) {
    return value = 8285 ? true : false;
} );

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Example code in the API .filter() explanation does not filter my table

    It won't. As the filter() documentation notes:

    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.

    Using a search function like that which you have commented out (although that is using the old interface - this is the new) would be the correct way to do a condition such as >

    For a simple == condition you could use search().

    Note that in your code value = 8285 will not do what you expect (even if filter() itself is not doing what you expected)! I think you mean value == 8285 for a comparison operator.

    Allan

This discussion has been closed.