fnGetData does not return the data in right order after column sorting in jquery DataTable?

fnGetData does not return the data in right order after column sorting in jquery DataTable?

motguptamotgupta Posts: 19Questions: 5Answers: 0
edited December 2012 in General
i am using jquery dataTable for displaying customer records. First time i go to customer page,i have 20 customer records in dataTable sorted by
customerId column( so they are diplayed starting from 20 to 1 where 20 is the id of 20th customer and 1 is the id of first customer) in desc
order. 20th customer is shown at top in dataTable.

now if do below in my javascript code

[code]
var customerTable=$('#customer').dataTable();// where customer is the html div associated with dataTable

var custData = customerTable.fnGetData(18)// it gives me data of 19 row in dataTable( as dataTable index starts from 0)
// so i get the data of customer having customer id=19
[/code]

Perfectly fine till here.

Now i click the sorting icon on customerId column . So after sorting customer with id as 1 is displayed on top in dataTable and customer with id as 20
will be displayed at bottom. Now i do the my javascript opration again

[code]
var customerTable=$('#customer').dataTable();

var custData = customerTable.fnGetData(18)
// it should give me data for customer id=2 Right? but still i am getting the old data i.e customer Data having id=19.
[/code]

i am not getting why i am not getting the right data after sorting? how should i get the correct data with row id after dataTable
sorting?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    fnGetData when given an integer will not return data for the current sorting order - it returns the data which is held at that position in the DataTables cache, which is _not_ altered based on sorting. If you want the data based on the current sort, Use the `_` method: `customerTable._()[18]` .

    Allan
  • motguptamotgupta Posts: 19Questions: 5Answers: 0
    edited December 2012
    Allan customerTable._()[18] returns undefined?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Sorry - it should be `_('tr')` - I forgot the selector: http://live.datatables.net/uweget/edit

    Allan
  • motguptamotgupta Posts: 19Questions: 5Answers: 0
    now it gives some weird error TypeError: a is null

    customerTable._('tr')[18]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Can you give me a link then? As you can see from my own link, it should work.
This discussion has been closed.