Dojo DataGrid (DGrid) Adding checkbox column

前端 未结 2 2040
鱼传尺愫
鱼传尺愫 2021-01-17 03:32

I am using Dojo Dgrid however i am trying to add a checkbox column however i am not sure of the approach.

Most of the tutorials i have been looking

相关标签:
2条回答
  • 2021-01-17 03:45

    If you want to have a column with checkboxes for the purpose of selecting rows, you should set your sights on the selector column plugin rather than editor. selector is specifically designed to render checkboxes (or radio buttons) in each cell that ties in to the Selection mixin when checked.

    See the documentation in the wiki, and the selector test page.

    0 讨论(0)
  • 2021-01-17 04:06

    you can also test this solution

    first you must add this Modules in require([]) section

    "dgrid/extensions/ColumnResizer",
                   "esri/request", "dgrid/OnDemandGrid", "dgrid/Selection", "dojo/store/Memory", "dgrid/selector",
    

    then define this array to hold your columns

     var columnsPol = []; 
    

    then add check box type column to array and any other type column to array

     columnsPol.push(
                 selector({ label: selector({}), selectorType: "checkbox" })
                );
    
    columnsPol.push({
                    label: "",
                    field: {any  name},
                    formatter: {a  function  for  formatting value  of cell},
                    width: "auto",
                    });
    
                    .
                    .
                    .
    

    then define your Grid and set properties

    var gridPol = new (declare([Grid, ColumnResizer, Selection]))({
         store: {your data},
         columns: columnsPol,
         minRowsPerPage: 40,
         maxRowsPerPage: 40,
         keepScrollPosition: true,
         selectionMode: 'none',
         allowSelectAll: true,
         loadingMessage: "Loading data...",
         noDataMessage: "No results found."
     }, {Id  for grid});
     gridPol.refresh();
    

    and then you can get selected and deselected rows

     gridPol.on("dgrid-select", function (event) {
               var selectedRows = event.rows;
               });
    

    and deselect

     gridPol.on.on("dgrid-deselect",function (event){
                var deselectedRows = event.rows;
                });
    
    0 讨论(0)
提交回复
热议问题