Slickgrid - One-click checkboxes?

前端 未结 6 2153
慢半拍i
慢半拍i 2021-02-13 13:05

When I create a checkbox column (through use of formatters/editors) in Slickgrid, I\'ve noticed that it takes two clicks to interact with it (one to focus the cell, and one to i

6条回答
  •  一向
    一向 (楼主)
    2021-02-13 13:37

    I used the onBeforeEditCell event to achieve this for my boolean field 'can_transmit'

    Basically capture an edit cell click on the column you want, make the change yourself, then return false to stop the cell edit event.

    grid.onBeforeEditCell.subscribe(function(row, cell) {                
                if (grid.getColumns()[cell.cell].id == 'can_transmit') {
                    if (data[cell.row].can_transmit) {
                       data[cell.row].can_transmit = false;
                    }
                    else {
                        data[cell.row].can_transmit = true;
                    }
                    grid.updateRow(cell.row);
                    grid.invalidate();
                    return false;
                }
    

    This works for me. However, if you're using the DataView feature (e.g. filtering), there's additional work to update the dataview with this change. I haven't figured out how to do that yet...

提交回复
热议问题