Custom filtering not working. Uncaught TypeError: Cannot read property 'push' of undefined error

Custom filtering not working. Uncaught TypeError: Cannot read property 'push' of undefined error

Azima1993Azima1993 Posts: 5Questions: 3Answers: 0
edited October 2017 in Free community support

I am trying to apply custom filtering to a table. But I am getting nothing, and I am getting 'Uncaught TypeError: Cannot read property 'push' of undefined' error in console.

 $.fn.dataTableExt.afnFiltering.push(
    function( oSettings, aData, iDataIndex ) {
        return (aData[0] == 'Alina Acharya') ? true : false;
      }
  );

var table = $('#checkin-checkout-record-table').dataTable({

    "bPaginate": true,
    "bLengthChange": true,
    "bFilter": true,
    "bSort": true,
    "bInfo": true,
    // "order": [[0, 'asc'], [4, 'asc']],
    "aLengthMenu": [50, 100],
    "bAutoWidth": false

}); 

table.draw();

What is wrong? I am using 1.10.0-dev version.

Answers

  • rf1234rf1234 Posts: 3,116Questions: 91Answers: 429

    Maybe try the newer version $.fn.dataTable.ext.search.push.
    Hope it works with your older data tables version. Here is an example from my own coding filtering multiple tables on one page. Data tables runs through this for every table on the page. Hence I need to check the rows passed in for "undefined" to identify the table and apply the respective filter.

    $.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex, row, counter) {
            if (typeof row.contract !== 'undefined') {
                if (row.contract.expired > '0') {
                    return filterShowNMonths(row.contract.exp_date);
                }
            } else {
                var selected = contractTable.row({selected: true});
                if (selected.any()) {
                    if (selected.data().contract.prolongation > '0') {
                        if ( typeof row.variable !== 'undefined' && 
                             typeof row.cashflow === 'undefined'    ) {
                            return filterExpElements(row.variable.end_date, 'VariableExpElementsButton', showVariableExpElements);
                        } else {
                            if ( typeof row.fixed !== 'undefined'&& 
                                 typeof row.cashflow === 'undefined'  ) {
                                return filterExpElements(row.fixed.end_date, 'FixedExpElementsButton', showFixedExpElements);
                            }
                        }
                    }
                }
            }
            return true;
        }
    );
    
    
  • allanallan Posts: 64,586Questions: 1Answers: 10,679 Site admin

    1.10.0-dev version.

    Ouch. Why? :).

    1.10.16 is the current release. I'd suggest you update.

    Allan

  • Azima1993Azima1993 Posts: 5Questions: 3Answers: 0

    thanks for the answer... I am beginning to make some progress now..

     $.fn.dataTable.ext.search.push(
        function( oSettings, aData, iDataIndex ) {
            return (aData[0] == 'Rakesh Mali') ? true : false;
        }
    );
    
    table.draw();
    

    But the function is returning false and filtering all rows, despite of rows with 'Rakesh Mali' being present.
    This is working fine with [http://jsfiddle.net/1hLcpr3x/132/].
    What is the problem, please help.

  • rf1234rf1234 Posts: 3,116Questions: 91Answers: 429

    Sorry, your jsfiddle produces a 404 error and I have no experience with the outdated data tables version you are using. Cannot help you.

  • allanallan Posts: 64,586Questions: 1Answers: 10,679 Site admin

    The 404 is because the forum is including the ]. in the link.

    I don't see Rakesh Mali in the data set at all, but the fiddle appears to be working properly as you state. We'd need to actually be able to see it not working to offer any help rather than seeing it working!

    If you are still using an old version of DataTables, update it. Very likely the dev version you are using didn't include all the features.

    Allan

This discussion has been closed.