Wrong result If count rows which contain a word

Wrong result If count rows which contain a word

Tabletable1234Tabletable1234 Posts: 2Questions: 0Answers: 0

Hello,

i have the problem, if i count rows that contain a word, the result is multiplied by 4 (Table has four columns), maybe someone can give me a tip what i missed:

"ajax": "array.txt",
"createdRow": function(row, data, dataIndex) {

var filteredData = dtable.column(1).data().filter( function ( value, index ) {
return includes("Word") ? true : false;
} );

document.getElementById('result').value = filteredData2.count(); // Works perfect

var filteredData2 = dtable.data().filter( function ( row ) {
return row.includes("Word") ? true : false;
} );
document.getElementById('result2').value = filteredData2.count(); // Result is multiplied by 4 (Table has four columns)


}


Replies

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    The count() docs state this:

    Therefore we must flatten arrays before being able to use the length property. This method does exactly that (i.e. it is a shortcut for api.flatten().length).

    If you have 4 columns then the result of filteredData2 will be a 2D array of 4 x the number of rows. Checkout this example:
    http://live.datatables.net/lavaduwu/1/edit

    Also you are missing value.includes() on line 5.

    Kevin

  • Tabletable1234Tabletable1234 Posts: 2Questions: 0Answers: 0

    Thanks for your help, i will try it.

This discussion has been closed.