0

I have data from an AJAX request in the format:

{
81920: {
  1: ['David Johnson'],
  2: ['Jarvis Landry', 'Mark Ingram']
},
38913: {
  1: ['Julio Jones', 'T.Y. Hilton', 'Jordan Howard'],
  2: ['David Johnson']
}

And I want to display it in a table, like (empty cells left blank):

Side 1        | Side 2
-----------------------------
David Johnson | Jarvis Landry
(empty cell)  | Mark Ingram
-----------------------------
Julio Jones   | David Johnson
T.Y. Hilton   | (empty cell)
Jordan Howard | (empty cell)
-----------------------------

I initialize the datatable with:

var trade_table;

trade_table = $('#trades').dataTable( {
      columns: [
          { title: "team1 gave" },
          { title: "team2 gave"}
      ],
      paging: false,
      info: false
    } );

And I want try to update it after my AJAX request with:

success: function(response) {
        // clear table and add new data
        $('#trades').dataTable().fnClearTable();
        $('#trades').dataTable().fnAddData(response);

      }

I can change the format of the data if needed to use just a list instead of a JSON, or some other format. Thanks!

2
  • Did you get chance to check this link? stackoverflow.com/questions/32750154/… Commented Dec 11, 2017 at 21:44
  • That helped me a bit, thanks! I decided to change the way I was returning data to return a string of players involved on each side, so now it's just a 2D array with no nested tables, which was simple to get working. Commented Dec 11, 2017 at 22:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.