How to show checkbox in datagrid dojo?

How to show checkbox in dojo datagrid?

+3
source share
6 answers

Use the format function as described in Widgets inside dojo.DataGrid
You can return a new dijit.form.Checkbox from the format function in dojo 1.4

+3
source

I would suggest setting cellType to dojox.grid.cells.Bool instead of formatting. Formatting gives you great freedom, but also the responsibility of collecting data from all the checkboxes (for all rows) afterwards, Something like this as a structure record should do the trick:

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

, (, ItemFileWriteStore), , , :)

+7

IndirectSelection EnhancedGrid, : http://jsfiddle.net/raybr/w3XpA/5/

+2

- , 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;
    },
+1

, true false. check box, cellType dojox.grid.cells.Bool , .

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

From the markup, do this for the desired result:

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

Source: https://habr.com/ru/post/1754091/


All Articles