filtering is not working for new rows after adding them dynamically in the datatable ...

filtering is not working for new rows after adding them dynamically in the datatable ...

ashwani_kumarashwani_kumar Posts: 4Questions: 2Answers: 0

This is my datatable initialization:

/**sheet is js object with an array of column's name in it. The first column is only for serial No. and last column is for action buttons i.e html type content in it. $sheet is the jQuery object of the table need to be converted into datatable **/

 function initDataTable(sheet) {

    var actionColumnIndex = sheet.sheetColumns.length - 1;

    var stringColumnsIndex = [];

    for (var i = 1; i < actionColumnIndex - 1; i++) {
        stringColumnsIndex.push(i);
    }
    return sheet.$sheet
            .dataTable({
                /* this will add row serial numbers in the datatable */
                "fnDrawCallback" : function(oSettings) {
                    /* Need to re-do the counters if filtered or sorted */
                    if (oSettings.bSorted || oSettings.bFiltered) {
                        for (var i = 0, iLen = oSettings.aiDisplay.length; i < iLen; i++) {
                            $(
                                    'td:eq(0)',
                                    oSettings.aoData[oSettings.aiDisplay[i]].nTr)
                                    .html(i + 1);
                        }
                    }
                },
                "aoColumnDefs" : [ {
                    "bSortable" : false,
                    "aTargets" : [ 0 ]
                }, {
                    "sType" : "html",
                    "aTargets" : [ actionColumnIndex ]
                }, {
                    "sType" : "number",
                    "aTargets" : [ 0 ]
                }, {
                    "sType" : "string",
                    "aTargets" : stringColumnsIndex
                } ],
                "iDisplayLength" : 5,
                "aLengthMenu" : [ [ 5, 10, 25, 50, -1 ],
                        [ 5, 10, 25, 50, "All" ] ],
                "aaSorting" : [ [ 0, 'asc' ] ],
                "bFilter" : true,
                "sScrollX" : "100%",
                "pagingType" : "full_numbers"/**
                                                 * 'First', 'Previous', 'Next'
                                                 * and 'Last' buttons, plus page
                                                 * numbers
                                                 **/
            });
}

The problem is::

the default filter will do filtering among only in the rows that are appended before converting that table into datatable but not able to filter the new dynamically added rows into the table.

I'm using fnAddData fnAddData(newRowData,true) function to insert row. /* /****newRowData** is an array of data for the row**/

any help is really appreciated... :)

Answers

  • ashwani_kumarashwani_kumar Posts: 4Questions: 2Answers: 0

    The problem is solved.
    Cause of the problem is I'm inserting Input text field for new entries and than replacing those fileds with the values but datatable still having input field in its data array.
    so I used fnUpdate function to update the data.

This discussion has been closed.