Slickgrid - One-click checkboxes?

前端 未结 6 2150
慢半拍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:51

    For futher readers I solved this problem by modifing the grid data itself on click event. Setting boolean value to opposite and then the formatter will display clicked or unclicked checkbox.

    grid.onClick.subscribe (function (e, args)
    {
        if ($(e.target).is(':checkbox') && options['editable'])
        {
            var column = args.grid.getColumns()[args.cell];
    
            if (column['editable'] == false || column['autoEdit'] == false)
                return;
    
            data[args.row][column.field] = !data[args.row][column.field];
        }  
    });
    
    function CheckboxFormatter (row, cell, value, columnDef, dataContext)
    {
        if (value)
            return '';
        else
            return '';
    }
    

    Hope it helps.

提交回复
热议问题