Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
{
    "afterInit" : function() {
        var hot = this;
        $(hot.rootElement).data("hot", hot);
    },
}

Image Modified

Figure 1: Enable handsontable instance

...

Code Block
languagejs
linenumberstrue
<div class="btn btn-primary" id="custom-check-all">Check All</div>
<div class="btn btn-primary" id="custom-invert-all">Invert All</div>


<script>
    $(function(){
        var hot = FormUtil.getField("field1").data("hot");
        $('#custom-check-all').on('click', function(){
            rowcount = hot.countRows();
            for(i = 0; i < rowcount - 1; i++){  // rowcount - 1 to ignore last row
                hot.setDataAtCell(i, 1, true);  // (row, column, value). column is 1 because checkbox is 2nd col in the table
            }
        })
        
        $('#custom-invert-all').on('click', function(){
            rowcount = hot.countRows();
            for(i = 0; i < rowcount - 1; i++){
                if(hot.getDataAtCell(i,1) == true){
                    hot.setDataAtCell(i, 1, false);
                }
                else{
                    hot.setDataAtCell(i, 1, true);
                }
            }
        })
    })
</script>

Image Modified

Figure 2: Insert Javascript code into Custom HTML

Step 3

Result:

Image Modified

Figure 3: Check all expected result

Image Modified

Figure 4: Invert all expected result

...