How to get a list of individual value from a datatable

How to get a list of individual value from a datatable

jadeite1000jadeite1000 Posts: 9Questions: 7Answers: 0

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

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    edited October 2018

    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:

    $('#creditCardTableId').DataTable().column(4).data();
    

    Cheers,

    Colin

  • jadeite1000jadeite1000 Posts: 9Questions: 7Answers: 0

    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))

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    edited October 2018

    console.log(('#creditCardTableId').DataTable().column(4).data())
    I am getting an undefined error.

    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 think filter() is what you are looking for.

    Kevin

This discussion has been closed.