11

I am using SlickGrid (https://github.com/mleibman/SlickGrid) to display an editable table, like this one, the one on the right: header span multiple columns

But seems currently SlickGrid does not support this, how can this be done?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
CGP
  • 303
  • 3
  • 8

2 Answers2

0

I found the following snippets from within the SlickGrid examples/example-column-group.html that worked for me. Note: I'm using this forked version of SlickGrid: https://github.com/6pac/SlickGrid/releases/tag/2.3.8

  1. Add the following options: (in addition to whatever options you already may be using)

var options = {
    createPreHeaderPanel: true,
    showPreHeaderPanel: true,
    preHeaderPanelHeight:23,
    explicitInitialization:true
};
  1. Add columnGroup property to each column you want to be grouped under a super-heading, for example:

var columns = [];
columns.push({ id: "col1", name: "Col 1", field: "col1",columnGroup:"SuperHeading" });
columns.push({ id: "col2", name: "Col 2", field: "col2", columnGroup: "SuperHeading" });
  1. Explicitly initialize grid using grid.init() , after you define your grid:

grid = new Slick.Grid("#myGrid", dataview, columns, options);

grid.init();
  1. Add this boiler-plate code:

var $preHeaderPanel = $(grid.getPreHeaderPanel())
    .addClass("slick-header-columns")
    .css('left', '-1000px')
    .width(grid.getHeadersWidth());
$preHeaderPanel.parent().addClass("slick-header");

var headerColumnWidthDiff = grid.getHeaderColumnWidthDiff();
var m, header, lastColumnGroup = '', widthTotal = 0;

for (var i = 0; i < columns.length; i++) {
    m = columns[i];
    if (lastColumnGroup === m.columnGroup && i > 0) {
        widthTotal += m.width;
        header.width(widthTotal - headerColumnWidthDiff)
    } else {
        widthTotal = m.width;
        header = $("<div class='ui-state-default slick-header-column' />")
          .html("<span class='slick-column-name'>" + (m.columnGroup || '') + "</span>")
          .width(m.width - headerColumnWidthDiff)
          .appendTo($preHeaderPanel);
    }
    lastColumnGroup = m.columnGroup;
}
Sam Denty
  • 3,693
  • 3
  • 30
  • 43
Tazdev
  • 1
  • 1
-1

You can create header in other div by html code. And then make slickgrid header height 0px.

$("#container").find(".slick-header").css("height","0px");

But don't forget make resizable=false in column options.

Nik
  • 121
  • 8