是否有可能在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}
。
此列仍可访问,并且与其关联的所有数据也应可用。
希望这会有所帮助!
在angular-slickgrid版本中,您可以执行以下操作1.在列定义中,包括所有列的2.在Present中,重新添加您想在网格中看到的列ID。现在加载页面并查看列选择器菜单。您将很高兴看到所有列。一些未选中
例如
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