0
votes

Let me start by saying I am VERY new to jQuery or any JavaScript programming so please excuse any noob-related mistakes.

I am creating a web app for my company using SlickGrid which will load a different dataset based on the users' role, so my fields will be defined by a dynamic sql query, rather than hard-coded.

I would like to apply Andrew Child's filter on the fork of SlickGrid to the lastest version of the master branch. The filter is displayed on this example: https://github.com/andrewchilds/SlickGrid/blob/master/examples/example15-fork-feature-demo.html

I created a control (using the pager control as a template) to add the filtering header elements. It looks great! Now I just need to make it functional. In following https://github.com/mleibman/SlickGrid/blob/master/examples/example4-model.html it looks like I need to modify this function to loop through the columns, return the filter type and column name, rather than hard-coding the filter type and column name.

function myFilter(item, args) {
  if (item["percentComplete"] < args.percentCompleteThreshold) {
    return false;
  }

  if (args.searchString != "" && item["title"].indexOf(args.searchString) == -1) {
    return false;
  }

  return true;
}

My questions are:

  1. Am I even close to being on the right track?
  2. If yes to 1, how do I modify myFilter() and dataView.compileFilter()?

Thanks for your help!

1

1 Answers

0
votes

Welcome to SO!

The filter function (myFilter in your case) gets applied to every item (row) in the DataView. If your columns are not hardcoded, you can get a list of columns using grid.getColumns(). As an example, take a look at my filter function:

function filter(item) {
  for (var columnId in columnFilters) {
    if (columnId !== undefined && columnFilters[columnId] !== "") {
        var c = grid.getColumns()[grid.getColumnIndex(columnId)];
        if(c.field == "...") {
            // return filtered items
        }
        else {
            // return false
        }
    }
  }
return true;
}

Here columnFilters is an array containing my values to be filtered.

Let me know if you have any questions.