dgrid 复选框未显示

dgrid Checkbox not showing

我尝试了很多变体,但出于某种原因,选择器复选框没有显示。谁能帮我解决这个问题。

下面是我使用的示例代码。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
    var djConfig = {
        parseOnLoad: true
    };
</script>
<script type="text/javascript" src="https://js.arcgis.com/3.16/" ></script>

<script type="text/javascript">
    require(["dojo/_base/declare", "dojo/_base/lang", "dojo/_base/array", "dojo/store/Memory", "dgrid/OnDemandGrid","dgrid/Selection", "dgrid/selector", "dstore/Trackable", "dojo/domReady!"],function (declare, lang, array, Memory, Grid, SelectionMixin, SelectorMixin, Trackable) {
            var CustomGrid = declare([Grid, SelectionMixin, SelectorMixin]);

            var data = [{
                    STRC_ID : "B988858",
                    Selected: false,
                    FNDG_CTGY_NB : "0010"
                }, {
                    STRC_ID : "B9811118",
                    Selected: true,
                    FNDG_CTGY_NB : "0020"
                }];

            var TrackableMemory = declare([Memory, Trackable]);
            var memory = new TrackableMemory({
                idProperty: "STRC_ID",
                data: data
            });

            var grid = new CustomGrid({
                store: memory,
                selectionMode: 'single',
                columns: getSTColumns(), 
                allowSelectAll: true
            }, 'gridHolder');
            grid.startup();

            function getSTColumns(){
                return {
                    col1: { label: "", selector: 'checkbox' },
                    col2: { label: 'STRC_ID', field: "STRC_ID", sortable: false },
                    col3: { label: 'FNDG_CTGY_NB', field: 'FNDG_CTGY_NB' }
                };
            };

           grid.refresh();

        });

</script>
</head>
<body>
    <div id="gridHolder"></div>
</body>
</html>

在此先感谢支持

这里是 link to jsBin.

我无法重现您的错误,但请尝试摆脱 getSTColumns() 函数并直接使用您的对象文字,例如:

    var grid = new CustomGrid({
        store: memory,
        selectionMode: 'single',
        columns: {
            col1: { 
                label: "",
                selector: 'checkbox'
            },
            col2: { label: 'STRC_ID', field: "STRC_ID", sortable: false },
            col3: { label: 'FNDG_CTGY_NB', field: 'FNDG_CTGY_NB' }
        }, 
        allowSelectAll: true
    }, 'gridHolder');
    grid.startup();

此外,还有一个现场演示,它提供了一些自动生成的源代码,这可能对您的初始设置很有用,更多信息可以在这里找到:http://dgrid.io/js/dgrid/demos/laboratory/

您正在尝试将选择器用作 mixin,因为它存在于 dgrid 0.4+ 中,但 ArcGIS 包括 dgrid 0.3,它不是 mixin,而是列插件(该概念在 dgrid 0.4 中已停用)。这也是为什么它有一个小写的s,在0.4+中不是这样。

这里是如何正确使用 0.3 的 selector 的示例,来自 0.3.17 selector docs:

require([
    "dojo/_base/declare", "dgrid/OnDemandGrid", "dgrid/Selection", "dgrid/selector"
], function(declare, OnDemandGrid, Selection, selector){
    var grid = new (declare([OnDemandGrid, Selection]))({
        store: myStore,
        selectionMode: "single",
        columns: {
            col1: selector({ label: "Select", selectorType: "radio" }),
            col2: "Column 2"
        }
    }, "grid");
    // ...
});