Search code examples
javascriptslickgridslick.jsdataview

Slick grid search using data view issue?


I'm using slick grid v2.2, In the grid I added search function to filter rows, below my code I used dataview for search, In the code "(gridFilter)" is not firing & throws error as Uncaught SyntaxError: Unexpected token ,, please correct my code if I'm wrong, Thanks in advance.

    $('#textSearch-inputEl').keyup(function ()   {
    if (e.which === 27) {
        this.value = "";
    }
    var searchList = $.trim(this.value.toLowerCase()).split(' ');
    dataView.setFilter(gridFilter);
    grid.invalidate();
    this.focus();

});

function gridFilter(rec) {
    var found;
    var gridSearchList = dataView.getLength();
    for (var i = 0; i < dataView.getLength(); i += 1) {
        found = false;
        $.each(rec, function(obj, objValue) {
            if (typeof objValue !== 'undefined' && objValue !== null
                    && 
            objValue.toString().toLowerCase().indexOf(gridSearchList[i]) !== -1) {
                found = true;
                return false; 
            }
        });
        if (!found) {
            return false;
        }
    }
    return true;
}

Solution

  • Try this code in gridFilter()

        var found;
        for (var i = 0; i < searchData.length; i += 1) {
            found = false;
            $.each(rec, function (obj, objValue) {
                if (typeof objValue !== 'undefined' && objValue !== null && objValue.toString().toLowerCase().indexOf(searchData[i]) !== -1) {
                    found = true;
                    return false;
                }
            });
            if (!found) {
                return false;
            }
        }
        return true;