Multiple tables, one Ajax source, different columns

Multiple tables, one Ajax source, different columns

mosleymosley Posts: 8Questions: 4Answers: 0

Refer to the link below. The first table has Name and Position columns, and the second table has Name and Salary columns - from one Ajax source. Is there an better way to do this?

http://live.datatables.net/yiluxude/10/edit

This question has an accepted answers - jump to answer

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    Your method of loading works fine. Why look any further?

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Are you basically asking if you have have it make the Ajax call only once? If so, there are two options:

    1. Make the Ajax call yourself ($.ajax) and then use data to pass the data into the tables (or rows.add() if you want to use the API).
    2. Have the first table make the request then use data() to get the data from it and rows.add() to add them to the second table.

    Allan

  • mosleymosley Posts: 8Questions: 4Answers: 0

    Yes, I am thinking to make the Ajax request only once. I figured this would be best. I am trying here (and learning), but definitely missing something.

    Going with your second method (first table makes the request) - see the following two links below. The first example populates my second table, but the second example doesnt. I presume it has to do something with the JSON data being in the wrong format, but I cannot figure it out.

    http://live.datatables.net/jesiroge/1/edit
    http://live.datatables.net/konimude/2/edit

    What am I missing?

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Remember that Ajax is asynchronous! You would need to wait for the table1 data to be loaded before you can use it...

    You can use the initComplete callback on the first table to do that.

    Allan

  • mosleymosley Posts: 8Questions: 4Answers: 0

    Ajax is asynchronous! You must state that a few does times in your documentation. Got it now. Thanks!

This discussion has been closed.