【问题标题】:UniformJS checkboxes not working in Handsontable?UniformJS 复选框在 Handsontable 中不起作用?
【发布时间】:2013-10-30 03:26:21
【问题描述】:

基本上,我在这里需要两件事。

一:uniformJS 风格化的复选框在 Handsontables 中不起作用。 二:我需要 Handsontable 标题中的复选框来“选中所有”相应列中的复选框。

我相信我可以通过 jQuery .append() 将复选框附加到表格中,但是有没有更正确的方法来处理 Handsontables?提前致谢。

http://jsfiddle.net/JNCFP/94/

jQuery

$('input').uniform();   


$(document).ready(function () {

  function getCarData() {
    return [
      {car: "Mercedes A 160", year: 2006, available: true, comesInBlack: 'yes'},
      {car: "Citroen C4 Coupe", year: 2008, available: false, comesInBlack: 'yes'},
      {car: "Audi A4 Avant", year: 2011, available: true, comesInBlack: 'no'},
      {car: "Opel Astra", year: 2004, available: false, comesInBlack: 'yes'},
      {car: "BMW 320i Coupe", year: 2011, available: false, comesInBlack: 'no'}
    ];
  }

  $("#example1").handsontable({
    data: getCarData(),
    startRows: 7,
    startCols: 4,
    colHeaders: ["Car", "Year", ""],
    colWidths: [120, 50, 60],
    columnSorting: true,
    columns: [
      {
        data: "car"
        //1nd column is simple text, no special options here
      },
      {
        data: "year",
        type: 'numeric'
      },
      {
        data: "available",
        type: "checkbox"
      }
    ]
  });

});

HTML

<input type="checkbox" checked /> Checkbox

<div id="example1" class="handsontable"></div>

【问题讨论】:

    标签: javascript jquery checkbox append handsontable


    【解决方案1】:

    您可以直接在可操作的 colHeaders 中的标题中添加“检查所有”,并应用 UniformJS,您需要像这样使用回调 afterRender

    $("#example1").handsontable({
    data: getCarData(),
    startRows: 7,
    startCols: 4,
    colHeaders: ["Car", "Year", "<input type='checkbox' class='checkall' />"],//checkall inside colHeaders
    colWidths: [120, 50, 60],
    columnSorting: true,
    columns: [
      {
        data: "car"
      },
      {
        data: "year",
        type: 'numeric'
      },
      {
        data: "available",
        type: "checkbox"
      }
    ],
    //afterRender so all the "available" checkbox use UniformJS 
      afterRender:function(){
          $('input').uniform(); 
          //click handler for .checkall
          $('.checkall').on('click', function () {
          //get all .htCheckboxRendererInput and change the property checked
              $(this).closest('table').find('input.htCheckboxRendererInput').prop("checked",this.checked);
              $.uniform.update();//update UniformJS
          });
      }
    });    
    

    http://jsfiddle.net/JNCFP/95/

    【讨论】:

      猜你喜欢
      • 2015-04-04
      • 2016-02-03
      • 2018-03-10
      • 2013-04-30
      • 2012-12-21
      • 2013-06-27
      • 2014-07-15
      • 1970-01-01
      相关资源
      最近更新 更多