Pregunta

Essentially, I need two things here.

One: uniformJS stylized checkboxes are not working in the Handsontables. Two: I need a checkbox in the Handsontable header to "check all" checkboxes in the corresponding column.

I believe that I can append a checkbox to the table via jQuery .append(), but is there a more correct way to go about this to work with Handsontables? Thanks in advance.

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>
¿Fue útil?

Solución

you can add the "check all" in the header directly in the handsontable colHeaders and to apply UniformJS you need to use the callback afterRender like this

$("#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/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top