Select all check box

Select all check box

pracede2005pracede2005 Posts: 10Questions: 0Answers: 0
edited September 2012 in General
I use datatable to display some data. Below the datatables table, i have a button "Tout selectionner" , When this button is clicked all check box must be selected but it does not work. Here is my code :
[code]
$(document).ready(function() {
oTable = $('#parameterList').dataTable( {

//"bServerSide": true,
"sAjaxSource":'/OCC/json/LoadPerimetre.action?'+params, // URL d'appel pour recuperer les datas json
"aoColumns": [ // definition de l'ordre et la largeur des colonnes
{ "mData": "nomGroupe","sWidth": "20%" },
{ "mData": "nomSousGroupe1","sWidth": "10%" },
{ "mData": "nomEntreprise","sWidth": "40%" },
{ "mData": "siren","sWidth": "25%" },
{ "mData": "selection","sWidth": "5%" }

]

} );
$('#selectAll').click( function() {
$('input', oTable.fnGetNodes()).attr('checked',this.checked);
} );
});

[/code]
My button code is :
[code]

[/code]
When i click in the button nothing is selected. But if a check a checkbox and click on the button selected become unselect.
Someone could help me ?
Thanks

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Does it work if you don't use DataTables? I'd be surprised if DataTables is interfering with that as your calls through the API look correct to me.

    Allan
  • pracede2005pracede2005 Posts: 10Questions: 0Answers: 0
    Allan thanks for your answer. I did some test without datatable and it does not work until i change the button into check box.
    Before
    [code][/code]
    After
    [code][/code]

    Is it normal ?
    Now it's working with check box instead of button.
  • dstarhdstarh Posts: 2Questions: 0Answers: 0
    this.checked in the case of the checkbox referes to the checkbox's state, the button has no such state.

    i think this is what you want http://jsfiddle.net/dstarh/MDqA7/
  • pracede2005pracede2005 Posts: 10Questions: 0Answers: 0
    Yes you're right. Thank you a lot.
This discussion has been closed.