默认情况下在SlickGrid中禁用列

时间:2014-10-30 08:03:14

标签: javascript slickgrid

我一直在环顾四周但是没有找到(这个非常明显的函数?)默认情况下在slickgrid中禁用列。

例如,我有以下网格:

Name    Age     City     Nickname

我希望例如,禁用city列,并仅在用户转到自定义列选择器时使其可见,并启用它。

由于

3 个答案:

答案 0 :(得分:0)

我这样做了。

var org_columns = [],hid_columns = [];
org_columns.push(
cb_selector.getColumnDefinition(),
{id: "id", name: "ID", field: "id", sortable: true, width: 56},
{id: "name", name: "Name", field: "name", editor: Slick.Editors.Text, sortable: true, width: 234},
{id: "email", name: "Email", field: "email", editor: Slick.Editors.Text, sortable: true, width: 234}
);

hid_columns.push(
cb_selector.getColumnDefinition(),
{id: "name", name: "Name", field: "name", editor: Slick.Editors.Text, sortable: true, width: 234},
{id: "email", name: "Email", field: "email", editor: Slick.Editors.Text, sortable: true, width: 234}
);
var data_view = new Slick.Data.DataView();
grid = new Slick.Grid("#grid", data_view, hid_columns, grid_options);
var columnPicker= new Slick.Controls.ColumnPicker(org_columns, grid,grid_options);

答案 1 :(得分:0)

类似于迟到的答案,但您可以在创建列选择器控件时传入另一个数组对象。

var defaultColumns = [
{id: "1", name: "1st Column" field: "Name"},
{id: "2", name: "2st Column" field: "Age"}
],
allColumns = [
{id: "1", name: "1st Column" field: "Name"},
{id: "2", name: "2st Column" field: "Age"}
{id: "3", name: "3st Column" field: "Gender"},
{id: "4", name: "4st Column" field: "Status"}
];

//create grid and pass in defaultColumns
 grid = new Slick.Grid("#List", dataView, defaultColumns, options)

//create the column control and pass in the allColumns
columnpicker = new Slick.Controls.ColumnPicker(allColumns, grid, options, "#List");

这将使用默认列初始化网格,并将控件设置为包含所有可用列。它看起来不像slickgrid wiki包含有关列选择器控件的正确文档,我只知道因为我必须深入研究代码并添加一个按钮来重置视图。

强制性参考链接:https://github.com/mleibman/SlickGrid/wiki/Slick.Grid

答案 2 :(得分:-1)

在SlickGrid的快速RTFM之后,我认为最简单的方法是使用JS / JQ操作它的类 - 正如您在开发人员工具中看到的那样,每个列和行都有定义行和列的类:

<div class="ui-widget-content slick-row even" style="top:0px"><div class="slick-cell l0 r0">Task 0</div><div class="slick-cell l1 r1">5 days</div><div class="slick-cell l2 r2">92</div><div class="slick-cell l3 r3">01/01/2009</div><div class="slick-cell l4 r4">01/05/2009</div><div class="slick-cell l5 r5">true</div></div>
<div class="ui-widget-content slick-row odd" style="top:25px"><div class="slick-cell l0 r0">Task 1</div><div class="slick-cell l1 r1">5 days</div><div class="slick-cell l2 r2">35</div><div class="slick-cell l3 r3">01/01/2009</div><div class="slick-cell l4 r4">01/05/2009</div><div class="slick-cell l5 r5">false</div></div>

来自:http://mleibman.github.io/SlickGrid/examples/example1-simple.html

所以应该很容易:)