Row to hide a row in dataTable ?

Row to hide a row in dataTable ?

arunnuvacarunnuvac Posts: 1Questions: 1Answers: 0

I need to add some custom filtering to the table. which include dynamically hiding showing of some rows in the table. I have constructed my table using DataTable. so i need a method to hide particular row from "row" object. So anyone can help me with it?

Answers

  • rf1234rf1234 Posts: 2,809Questions: 85Answers: 406

    use $.fn.dataTable.ext.search.push. Return "true" for rows you want to show and "false" for rows you want to hide.

    It will be run for all of your datatables on your page. You need to be careful if you have mutliple data tables on the same page. For that reason I check for "undefined" in the example below.

    This example works with multiple tables on the same page:

    $.fn.dataTable.ext.search.push(
        function (settings, data, dataIndex, row, counter) {
            //we only look for the contract table
            //all current contracts are displayed; expired can be selected
            //by month ago
            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()) {
                    //in case it is a prolongation the expired components are filtered
                    //out by default (redraw upon select of contract raw and also upon push button)
                    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;
        }
    );
    
This discussion has been closed.