getting the first row

getting the first row

eflateflat Posts: 3Questions: 0Answers: 0
edited November 2011 in General
When my page comes up and the datatable is drawn, I want to get the first row of data. I tried fnGetData(0) -- it seems to be returning the first item of raw table data before sorted by datatables

Using firebug, I was able to get what I want like this:
[code]console.log(oTable.dataTableSettings[0].aoData[ oTable.dataTableSettings[0].aiDisplay[0] ]._aData[0]);[/code]
BUT...I'm not sure I should be accessing things like that. Is there a clean way to do this through the api??

Replies

  • OmnimikeOmnimike Posts: 22Questions: 0Answers: 0
    edited November 2011
    .fnGetNodes(0) might be what you are looking for. It might not get you the top tr of the table depending on whether the rows have been sorted or filtered. Another way would be
    [code]
    $('tr', oTable.fnSettings().nTBody)[0]
    [/code]
    I've never needed to do something like that, so I can't tell you if that's going to work properly or not.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    [code]
    oTable.fnGetData( $('#example_table tbody tr:eq(0)')[0] );
    [/code]

    is how I would recommend doing it. Basically you want a reference to the first TR in the TBODY, which you can get using getElementsByTagName or jQuery as I've done above - and then pass that in to fnGetData.

    Allan
  • abhiraamabhiraam Posts: 8Questions: 0Answers: 0
    Hi Allan,

    I have to get only 1st column value of N number of rows in data table, can you help me in this.
    presently i am using oTable.fnGetNodes() here, I am getting all the column values in a row that will be huge data because of that browser is alerting stop scripting.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    The fnGetColumnData plug-in might be ideal for you: http://datatables.net/plug-ins/api#fnGetColumnData

    Allan
  • abhiraamabhiraam Posts: 8Questions: 0Answers: 0
    Thanks Allan,

    But my 1st column in table is checkbox here, I am not able ready the value of checkbox checked, var input=jQuery('input:checkbox:checked', oTable.fnGetNodes()); I am getting input has 0 kindly help me.
  • abhiraamabhiraam Posts: 8Questions: 0Answers: 0
    var input=jQuery('input:checkbox:checked', oTable.fnGetNodes());
    this is returning me some value but


    var input = jQuery('input:checkbox:checked', oTable.fnGetColumnData()); this is not returning any value to me.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > var input = jQuery('input:checkbox:checked', oTable.fnGetColumnData()); this is not returning any value to me.

    It wouldn't since that is working with strings not nodes.

    What you can do is (note that this needs DataTables 1.9):

    [code]
    $('#example').dataTable().$('td:nth-child(1) input:checked')
    [/code]

    that should do it :-)

    Allan
  • abhiraamabhiraam Posts: 8Questions: 0Answers: 0
    Currently I am using DT 1.8, In this version How can I resolved the issue kindly give me some hint.
    IE 8 browser is not supporting for rendering of 1500 data in datatable
    if i used oTable.fnGetNodes().
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    You would just do something like:

    [code]
    nodes = $('#example').dataTable().fnGetNodes();
    $('td:nth-child(1) input:checked', nodes);
    [/code]

    but it is worth upgrading to 1.9 (full release of 1.9.0 soon).

    > IE 8 browser is not supporting for rendering of 1500 data in datatable

    1000-2000 is about the limit for IE8 with client-side processing because it is so slow. You might want to consider Ajax loading data with deferred rendering or server-side processing.

    Allan
  • abhiraamabhiraam Posts: 8Questions: 0Answers: 0
    Hi Allan,

    A.I want to delete complete row of tbody of my datatable without deleting header and foot, I am trying lot but not able find how to do this,kindly help me over this issue.

    B.I want to delete specfic row of DataTable of tbody can you please provide the query for this.
  • michandrzmichandrz Posts: 12Questions: 0Answers: 0
    edited February 2012
    i would use the fnDrawCallback and do something like this:
    [code]http://datatables.net/forums/discussion/7277/getting-the-first-row
    $('table#fp').dataTable( {

    "sDom" : 'lrtfp',
    "bPaginate" : false,
    "bProcessing": false,
    "bstatesace" : true,
    "sAjaxSource": './data.php?request=fp',
    "fnDrawCallback": deleteRow
    }
    function deleteRow(oSettings) {
    //replace the 1 with the row # you wish to delete note that this fuction uses CSS
    //style counting starting from 1
    $(oSettings.nTable).children("tr:nth-child(1)").remove();
    }
    [/code]
    *note code not tested
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > A.I want to delete complete row of tbody of my datatable without deleting header and foot, I am trying lot

    Use fnDeleteRow (unless you are using server-side processing, in which delete the row at the server and then redraw the table with fnDraw ).

    > B.I want to delete specfic row of DataTable of tbody can you please provide the query for this.

    Again use fnDeleteRow with client-side processing tables. Just give the function the TR node you want to delete, as noted in the documentation.

    Allan
  • abhiraamabhiraam Posts: 8Questions: 0Answers: 0
    Hi Allan,

    How to get the length of column in datatable dynamically in javascript method.
  • abhiraamabhiraam Posts: 8Questions: 0Answers: 0
    Sorry Allan I got the answer for my previous Question.

    But I have one more doubt about grouping,
    assume i have 20 rows in that 1st 5 rows of belongs to Firefox, next 5rows belongs to IE,
    next 5 rows belong chorme and last 5rows belong to safari. In this condition i dont wont to display all twenty rows, I like to dispaly only Group name of browser(i.e one 4 rows of browser) can you help me in that please.

    Thanks,
    Abhi.
This discussion has been closed.