在DOJO中隐藏数据网格列

时间:2015-01-19 11:41:56

标签: javascript dojo dojox.grid.datagrid dojox.grid

您好我想隐藏数据网格中的列名,并希望将其用于某些内部功能,以便用户无法看到它。 例如我想隐藏卷号字段请帮我做。我希望问题足以解释我需要做的工作。 请帮我解决一下这个。提前致谢! 请找下面的代码:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
            pageEncoding="ISO-8859-1"
        %>
<!DOCTYPE html>
<html>
<head>
<script>

function onReportTypesSelect()
{
    if(getDijitValue('data_types') != 'Select')
        {

        if(getDijitValue('data_types') == 'class_level')
        {
            require([
                        "dojo/store/JsonRest",
                        "dojo/store/Memory",
                        "dojo/store/Cache",
                        "dojox/grid/DataGrid",
                        "dojo/data/ObjectStore",
                        "dojo/query",
                        "dojo/domReady!"

                    ], function(JsonRest, Memory, Cache, DataGrid, ObjectStore, query){
                        var userStore, dataStore, grid;
                        userStore = new Cache(JsonRest({target: "<%=request.getContextPath()%>" + "/data/classServlet"}), new Memory()); 
                        grid = new DataGrid({
                            id:"class_level_grid",
                            store: dataStore = new ObjectStore({objectStore: userStore}),
                            structure: [
                                        {name: 'Roll Number', field: 'roll', width: 'auto', defaultValue: ""},
                                         {name: 'Name', field: 'name', width: '100px', defaultValue: ""},
                                        {name: 'Class', field: 'class', width: '75px', defaultValue: ""}
                            ],
                        style:"font-family: calibri, Garamond, Comic Sans; font-size: 10;",
                        selectionMode:'single',  
                        autoHeight: 10,
                        rowsPerPage:40,
                        rowSelector:'20px',
                        selectable: true
                        }

                        , "class_level_grid_div"); // make sure you have a target HTML element with this id
                        grid.startup();

                    });

        }
}
}
</script>
</head>`enter code here`
<body>
<div id="data_types" data-dojo-type="dijit/form/Select" style="width: 200px;" onchange="onReportTypesSelect()">
                     <span data-dojo-value="Select"><b>Select</b></span>
                    <span data-dojo-value="class_level"><b>class Level</b></span>
</div>
<div id="class_level_grid_div" style="width: 95%; height: 90%;"> </div>
</div>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

首先,指定专栏id

{name: 'Roll Number', id: 'rollNum', field: 'roll', width: 'auto', defaultValue: ""},

如果您试图隐藏或显示列,解决方案是:

// to hide column with id="rollNum"
grid.styleColumn("rollNum", "display: none;");

// to show it
grid.styleColumn("rollNum", "display: table-cell;");

答案 1 :(得分:1)

非常简单。只需添加&#34;隐藏:true&#34;到列结构。

结构:[                                         {name:&#39; Roll Number&#39;,field:&#39; roll&#39;,width:&#39; auto&#39;,defaultValue:&#34;&#34; ,隐藏:true },                                          {name:&#39; Name&#39;,field:&#39; name&#39;,width:&#39; 100px&#39;,defaultValue:&#34;&#34;},                                         {name:&#39; Class&#39;,field:&#39; class&#39;,width:&#39; 75px&#39;,defaultValue:&#34;&#34;}                             ],

相关问题