testing for data in a datatable

testing for data in a datatable

dinotomdinotom Posts: 27Questions: 7Answers: 0
edited May 2014 in DataTables 1.10

I am new to datatables so this may be child play for everyone but I've just started with it.

I am populating a datatable on page load in my code behind. When an updated record is posted (via clientside script) I want to test for data in the table, if there is data then I want to add a row to the current data and if not, then load the tables data via AJAX. I found some examples using the code below below to test if table has data but I get an "Uncaught typeError" undefined is not a function error.

[code]<br />
if (ideaTable.fnGetData().length > 0) { 'error is on this line <br />
var rowNode = ideaTable
.row.add(postedData)
.draw()
.node();
<br /> //use this if you want to highlight the added row <br />
$(rowNode)
.css('color', 'red')
.animate({ color: 'black' });
} else { <br />
// if it doesn't, bind this as its first data<br />
// intitalize datatable with data called via ajax
}<br />
[/code]

This question has an accepted answers - jump to answer

Answers

  • dinotomdinotom Posts: 27Questions: 7Answers: 0

    Seriously? No one knows how to test if a table has data bound to it?

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Answer ✓

    I'm sure lots of people know, but no one has had a chance to reply yet. It would help if you linked to a test case as requested in the forum rules.

    If you are getting an error from ideaTable.fnGetData() then ideaTable probably isn't a jQuery DataTables object. But without being able to see all of the code, I don't know what it is. I'm guessing, from the rest of your code that it is a DataTables API instance. In which case use ideaTable.data().length . Example: [http://live.datatables.net/nudecin/1/edit][(http://live.datatables.net/nudecin/1/edit).

    Allan

  • dinotomdinotom Posts: 27Questions: 7Answers: 0

    thank you and thank you for the library

This discussion has been closed.