Search code examples
javascriptrazordatatable

Error getting row of data from DataTable when searching


I'm having trouble getting the following code to work. I have a table and wish to search the table for some data and return the row of data/array with the matching string (field13a). When running the code I get the following error:

outputReferenceError: filteredData is not defined

I have no idea what "filteredData" is

Code:

var field13a = field13.substring(0, 4); 
var indexes = locTable
    .rows()
    .indexes()
    .filter(function (value, index) {
        return field13a === locTable.row(value).data()[0];
    });

console.log(locTable.rows(indexes).data().toArray());

Not sure where I am going wrong, I have looked on Internet but not had any luck finding the best way to fix this or a better solution. Thank you.


Solution

  • Not sure what the error was but ended up using this:

    var names = locTable
        .rows(function ( idx, data, node ) {
            return data[1] === field13a ?true:false;
        } )
        .data();
    console.log(names[0]);