How to Iterate through (array) the below given content to load in two datatables.

How to Iterate through (array) the below given content to load in two datatables.

shaibaazshaibaaz Posts: 3Questions: 1Answers: 0
edited September 2016 in Free community support
{
    "**OutStandings**": [
        [null, null, null, null, null, "Shenzhen Wheeltopn Intl Transportation Co.ltd", "USD", 80.00],
        [null, null, null, null, null, "Shenzhen Wheeltopn Intl Transportation Co.ltd", "RMB", 200.00],
        [null, null, null, null, null, "Shenzhen Wheeltopn Intl Transportation Co.ltd", "USD", 200.00], null
    ],
    "**OrgBankInfo**": [
        [3, "Shenzhen Wheeltopn Intl Transportation Co.ltd", "Luohu", "Bank Of China  ", "Shenzhen Dongmen", "744557960885(USD)", null, "BKCHCNBJ45A", null],
        [3, "Shenzhen Wheeltopn Intl Transportation Co.ltd", "Luohu", "Bank Of China ", "Shenzhen Dongmen", "749757929717(RMB)", null, "BKCHCNBJ45A", null], null
    ]
}

I have used Ajax call to a webmethod, where I add two tables to a dataset and return as string (Array) using Json serialize. The string in the question is the string returning to datatables(jquery). I am able to get the string in "response.d" but after that I am finding it difficult to iterate through the string and populate two data tables. I would be really thankful if anyone could sort this out. Thanks.

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • shaibaazshaibaaz Posts: 3Questions: 1Answers: 0

    I have used Ajax call to a webmethod, where I add two tables to a dataset and return as string (Array) using Json serialize. The string in the question is the string returning to datatables(jquery). I am able to get the string in "response.d" but after that I am finding it difficult to iterate through the string and populate two data tables. I would be really thankful if anyone could sort this out. Thanks.

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    I'm not sure what data from the above you want to display in the DataTable. Is each entry in **OutStandings** a row in the table? If so, use ajax.dataSrc to tell DataTables that fact.

    Allan

  • shaibaazshaibaaz Posts: 3Questions: 1Answers: 0
    edited September 2016

    Yes Sir, Each entry in OutStandings is a row in table.
    Same is the case for OrgBankInfo.
    So I have two tables to populate.

    Just need to know how to go about it.

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Okay, you can't use DataTables own ajax option to populate two different tables form the same Ajax source file. You need to make your own Ajax call ($.ajax for example) and then use rows.add() to add the rows to the table.

    Allan

This discussion has been closed.