fnGetData for invisible rows

fnGetData for invisible rows

rndinfrndinf Posts: 9Questions: 0Answers: 0
edited May 2012 in General
Hi Allan,
Need your help in figuring out below datatable situation.

I need to get data for 10 rows at a time from the datatable and display certain fields from those rows on page
When user clicks my next button , need to get data for next 10 rows. Im using fnGetData as
for( i=0 ; i< 10 ; i++)
{
var aData = oTable.fnGetData(i);
$('#txtfield1').append(aData[0]);
}

Works fine for 10 rows as datatable is displaying 10 rows, fails afterwards.
User will NOT be clicking DATATABLE to display next 10 rows , so how should I get the next 10 invisible rows
as many times as user clicks on next button.
Cannot use var oTable.fnGetPosition(i) along with fnGetData , as user will not be clicking on DATATABLE itself.
Will appreciate any pointers....
thx

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Use fnGetData without passing any parameters and you'll get the data for the entire table. You can then run through that. Also look at the _ (underscore) function which is useful for getting data with a jQuery selector.

    Allan
  • rndinfrndinf Posts: 9Questions: 0Answers: 0
    Thx for your resp Allan, I already tried that as below,

    aData=oTable.fnGetData();

    $(aData).each(function() {
    var nextRow = new Array();
    aReturn.push( nextRow );
    });


    alert ( "Table row count " + aReturn.length);

    And it display row count as 10 ( although table has total of 300 rows, with 10 displayed)
    I am using Datatables 1.8.2
    Is there something that I am missing
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Can you link to a test page please? It sounds lot me like you might be using server-side processing, in which case DataTables only knows about the rows which are on the page. If you are using only 300 rows, then server-side processing really shouldn't be needed (50,000+ rows then yes).

    Allan
  • rndinfrndinf Posts: 9Questions: 0Answers: 0
    ur correct I am using

    "bServerSide": true,
    "sAjaxSource": "myproj/ws/getData"

    so should I not use "bServerSide" and use $.ajax( { to get data for the table
  • rndinfrndinf Posts: 9Questions: 0Answers: 0
    or could i use "aaData": myjsonarray ( whic I can return throught getJSON call)
  • rndinfrndinf Posts: 9Questions: 0Answers: 0
    I tried this after yourinitial pointer

    $('#filter').live('click', function() {

    getData();
    }

    function getData (){
    var jqxhr=$.getJSON('/myproj/ws/getData?', function(json) { })
    .success(function(jsondata) {
    alert('retrieved check data');

    reloadDataTables(jsondata)

    })
    .error(function() {
    alert('unable to retrive data');

    })
    .complete(function(json) {

    });

    }

    function reloadDataTable(jsondata) {
    oTable = $('#checkItems').dataTable( {
    "bProcessing": true,
    "aaData": jsondata.aaData,
    });

    }

    But I m getting "Object expected jQuery.js line 16 character 15511

    jQuery.js is jQuery JavaScript Library v1.6.2
    Im using Datatable 1.8.2

    Once again any pointer will help.. thx
  • rndinfrndinf Posts: 9Questions: 0Answers: 0
    Hi Allan,
    Need your help in figuring this out,

    I did not want to do fnGetData() ( without args) and traverse through ALL the table rows so I tried something as listed below


    oTable = $('#myTable').dataTable( {

    "aaData": myaaData, // myyaaData is rec from server through getJSON call
    "bProcessing": true,
    "aLengthMenu": [10, 25, 50, 100, 250],
    "sPaginationType": "full_numbers",
    "aoColumnDefs": [{"bSortable": true, "bSearchable": true, "aTargets": [0]},
    {"sClass": "dt-number dst-currency dst-USD numeric-comma", "aTargets": [5]},
    {"sClass": "dt-datetime dst-date", "aTargets": [6]},

    });


    so bServerSide = false,
    now if I try to get row data as below, for row that is NOT currently visible on the table as below,


    rowindex = oTable.fnGetPosition( $("#myId").get(0) ) ;
    aData=oTable.fnGetData(rowindex);


    I am getting ==> 'nodeName' is null or not an object

    Could you please point me in the right direction.
    Thanks for your help.
This discussion has been closed.