incorrect result using fnGetNodes() after a value is searched in searchbox of jquerydataTables1.9.4

incorrect result using fnGetNodes() after a value is searched in searchbox of jquerydataTables1.9.4

PallaviPallavi Posts: 8Questions: 0Answers: 0
edited January 2014 in DataTables 1.9
I am using jquery.dataTables.js(1.9.4).
I am using checkbox for select all and deselect all,but I wanted checked value of checkbox of all pages to be persisted so I used

[code]
$(xytable.fnGetNodes()).find("input[name='chklist']").length //to get length of checkboxes
and

$(xytable.fnGetNodes()).find("input[name='chklist']:checked").length // to find length of checked checkboxes
[/code]

here xytable -->table id

but when I search a value in search box then the content changes say from 8 results their are only 2 result displayed(which is correct) but the length I get of all the checkboxes by fnGetNodes() remain 8 and not 2(which is incorrect) !!!!

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Can you please link to a test case as noted in the forum rules. I'm not sure why that wouldn't work.

    Allan
  • PallaviPallavi Posts: 8Questions: 0Answers: 0
    hey have provided js fiddle link

    http://jsfiddle.net/Pallavik/pJG9f/45/

    here length remains 6,even if 1 result(checkbox) is displayed when 'g' is searched in Search Box and 'Click here to check length' is clicked.
  • PallaviPallavi Posts: 8Questions: 0Answers: 0
    edited January 2014
    js fiddle I created is just to show the problem

    I have used definitions for dataTable as

    [code]
    oTable=$("#tablename").dataTable({
    "bProcessing":true ,
    "sProcessing":"Processing",
    "iDisplayLength": 5,
    "aoColumnDefs": [
    { 'bSortable': false, 'aTargets': [ 0,4 ]}
    ] ,
    "bPaginate": true,
    "sPaginationType": "input",
    "bInfo": false,
    "bAutoWidth": false,


    });
    [/code]

    is anything in definition causing trouble?
  • PallaviPallavi Posts: 8Questions: 0Answers: 0
    js fiddle I created is just to show the problem

    I have used definitions for dataTable as

    [code]
    oTable=$("#tablename").dataTable({
    "bProcessing":true ,
    "sProcessing":"Processing",
    "iDisplayLength": 5,
    "aoColumnDefs": [
    { 'bSortable': false, 'aTargets': [ 0,4 ]}
    ] ,
    "bPaginate": true,
    "sPaginationType": "input",
    "bInfo": false,
    "bAutoWidth": false,


    });
    [/code]

    is anything in definition causing trouble?
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Ah I understand now - so you want only the nodes which are currently visible to be selected? In which case, don't bother with fnGetNodes - just use `$('input[name='checklist']')` . Or do you want something more complicated than that? What about paging?

    Allan
  • PallaviPallavi Posts: 8Questions: 0Answers: 0
    edited January 2014
    thanks for ur prompt response

    I don't want only currently visible ones as I have used pagination .

    In short I want total length of the checkboxes (including in 2nd,3rd etc pages)after search is applied and total length of checkboxes which are checked(after search is applied).
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    In which case use the $ API method - http://datatables.net/docs/DataTables/1.9.4/#$ - specifically the `filter` option - set it to `applied` .

    Allan
  • PallaviPallavi Posts: 8Questions: 0Answers: 0
    hey thanks for the solution!!!!!works smoothly

    used

    [code]
    oTable._("input[name='chklist']", {"filter":"applied"}); //to find all my checkboxes
    //and
    oTable._("input[name='chklist']:checked", {"filter":"applied"}); //to find all my checked checkboxes
    [/code]
This discussion has been closed.