How to show a checkbox in a dojo datagrid?

浪尽此生 提交于 2019-12-12 09:54:17

问题


How to show a checkbox in a dojo datagrid?


回答1:


Use formatter function as described in Widgets Inside dojo.DataGrid
You can return new dijit.form.Checkbox from formatter function in dojo 1.4




回答2:


I would suggest setting cellType to dojox.grid.cells.Bool, instead of the formatter.The formatter gives you much freedom, but also the responsibility of gathering the data from all the checkboxes (for all the rows) afterwards. Something like this as a structure-entry should do the trick:

{
   name: "is awesome?",
   width: "auto",
   styles: "text-align: center",
   type: dojox.grid.cells.Bool, editable: true
}

Please make sure to use a write-store (like ItemFileWriteStore) and not just a read-store, otherwise you will be disabled to actually check the checkbox :)




回答3:


You need the IndirectSelection plugin for the EnhancedGrid, here's a fiddle: http://jsfiddle.net/raybr/w3XpA/5/




回答4:


You can use something like this, with Json

HTML

<table id="myGrid" dojoType="dojox.grid.DataGrid"
               clientSort="true" autoHeight="true" autoWidth="true">
            <script type="dojo/method">
                showFields();
            </script>
</table>

DOJO

    showFields:function () {
        dojo.xhrPost({
            url:"/getFields.do",
            timeout:2000,
            handleAs:"json",
            load:dojo.hitch(this, "displayInGrid")
        });
    },

    displayInGrid:function (jsonResult) {
        var dataStore = new dojo.data.ItemFileReadStore(
            { data:jsonResult }
        );
        var checkboxLayout = [
            [
                {name:'ID', field:"id" },
                {name:'Value', field:"id", formatter:this.addCheckBox}
            ]
        ];
        var grid = dijit.byId("myGrid");
        grid.setStructure(checkboxLayout);
        grid.setStore(dataStore);
    },

    addCheckBox:function (val) {
        var checkbox = "<input type='checkbox' name='myfields' value='" + val + "/>";
                    return checkbox;
    },



回答5:


If you are trying to show a checkbox selector on each row of the grid you can follow this tutorial

http://dojotoolkit.org/documentation/tutorials/1.8/working_grid/demo/selector.php




回答6:


If the type of the cell is a boolean, then its value is displayed as either the string true or false. If a check box is desired, setting the cellType to be dojox.grid.cells.Bool and marking it as editable will make a checkbox appear.

http://dojotoolkit.org/reference-guide/1.9/dojox/grid/DataGrid.html#editing-cells

From markup, do like this for the desired result:

<th field="booleanField"  cellType="dojox.grid.cells.Bool"  editable="true">Checkbox field</th>


来源:https://stackoverflow.com/questions/3222893/how-to-show-a-checkbox-in-a-dojo-datagrid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!