How to get a list of individual value from a datatable
How to get a list of individual value from a datatable
Hi All:
I have a datable called "creditCardTableId" that have 100 records, column 4 have a balance column where user enter a value for each balance. I needed to get the 100 records for each balance the user enter and see if the value is greater than 100 or less than .10 cents.
I tried to use $('#creditCardTableId') outside of the datatable but not sure how to do it?
This example used a callback:
https://datatables.net/examples/advanced_init/footer_callback.html
But I am not sure how to use the "api.column(4).data()" if I am outside of the database.( javascript code called outside of the datatable definition")
Answers
Hi @jadeite1000 ,
I'm not sure what you mean by "if I am outside of the database"- but if you just want to use the API, you would do something like:
Cheers,
Colin
Hi Colin:
Thank you for the quick reply.
In this code I added the following line after the last javascript:
https://datatables.net/examples/advanced_init/footer_callback.html
console.log(('#creditCardTableId').DataTable().column(4).data())
I am getting an undefined error.
When I do the following I don't get an undefine error but an object but I can't seem to find the api that will give me the array of data.
console.log(('#creditCardTableId').DataTable().column(4))
Its hard to say what the problem is without seeing your code. The only thing I can think of is that you don't have a column 4. Columns start counting at 0.
I put one together that demonstrates the API that Colin suggested.
http://live.datatables.net/pixahutu/1/edit
Plus it show the use of the
filter()
API to get the rows that meet a certain condition. The age column is between 60 and 70 in this case. I thinkfilter()
is what you are looking for.Kevin