在SlickGrid中是否可以有一个隐藏的列?所谓隐藏列是指我想为每一行保存一些数据,但我不希望这些数据显示在网格上。
数据和网格中的列之间不存在隐含关系-两者完全独立。因此,您的数据可以包含比实际绑定到网格列更多的字段。
示例:
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);
})
我的data
数组包含start
和finish
字段,但我选择在创建columns
数组时将它们排除在外。
grid.setColumns
来实现-假设您在声明网格时设置了columns={id,a,b,c}
;在网格初始化之后,您可以调用grid.setColumns(newColumns)
,其中newColumns
是新的列数组,不包括id- newColumns = {a,b,c}
。 this.columnDefinitions = [
{ id: 'name', name: 'Name', field: 'name', filterable: true, sortable: true },
{ id: 'duration', name: 'Duration', field: 'duration', filterable: true,sortable: true },
{ id: 'complete', name: '% Complete', field: 'percentComplete', filterable:true,sortable: true }
];
this.gridOptions = {
presets: {
// the column position in the array is very important and represent
// the position that will show in the grid
columns: [
{ columnId: 'duration', width: 88, headerCssClass: 'customHeaderClass' },
{ columnId: 'complete' }
]
// name will be present in the menu but not on the grid