Search code examples
jqueryslickgrid

how to add hidden column in slickgrid


Is it possible to have a hidden column in slickgrid? By hidden column I mean I want to save some data for each row, but I don't want this data to be shown on the grid.


Solution

  • There is no implied relationship between the data and the columns in the grid - the two exist completely independent of each other. So your data can contain many more fields than are actually bound to grid columns.

    Example:

    var grid;
    var columns = [
      {id: "title", name: "Title", field: "title"},
      {id: "duration", name: "Duration", field: "duration"},
      {id: "%", name: "% Complete", field: "percentComplete"},
      {id: "effort-driven", name: "Effort Driven", field: "effortDriven"}
    ];
    
    var options = {
      enableCellNavigation: true,
      enableColumnReorder: false
    };
    
    $(function () {
      var data = [];
      for (var i = 0; i < 500; i++) {
        data[i] = {
          title: "Task " + i,
          duration: "5 days",
          percentComplete: Math.round(Math.random() * 100),
          start: "01/01/2009",
          finish: "01/05/2009",
          effortDriven: (i % 5 == 0)
        };
      }
    
      grid = new Slick.Grid("#myGrid", data, columns, options);
    })
    

    Here my dataarray contains fields start and finish but I have chosen to exclude them when creating my columns array.