do we have an option of displaying dictionary in datatables ?

do we have an option of displaying dictionary in datatables ?

schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

public Dictionary<string,Dictionary<decimal,List<BatchViewModel>>> ProductionBatches { get; set; }
I want to display this data in dattables

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    Is the dictionary to be displayed in a td or is it to populate the table?

    To display in a td you can use columns.render to convert it from an object to a string to be displayed.

    If its for the table then you will need to convert it to an array where each element contains the row data. See the Data docs for details.

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0

    It is for datatable and the values are showing up like this
    {
    "X":{
    "y":{
    "z":[
    {
    "Property1":"value1",
    "Property2":"value2",
    "Property3":"value3 ",
    "Property4":"value4",
    "Property5":"value5",
    "Property6":"value6",
    "Property7":value7,
    "Property8":"value8 ",
    "Property9":value9,
    "Property10":value10,
    "Property11":value11,
    "Property12":"value12",
    "Property13":value13,
    "Property14":value14,
    "Property15":"value15",
    "Property16":"value16",
    "Property17":"value17",
    "Property18":"value18",
    "Property19":value19,
    "Property20":value20,
    "Property21":value21
    }
    ]
    },
    "Y1":{
    "Z1":[
    {
    "Property1":"value1",
    "Property2":"value2",
    "Property3":"value3 ",
    "Property4":"value4",
    "Property5":"value5",
    "Property6":"value6",
    "Property7":value7,
    "Property8":"value8 ",
    "Property9":value9,
    "Property10":value10,
    "Property11":value11,
    "Property12":"value12",
    "Property13":value13,
    "Property14":value14,
    "Property15":"value15",
    "Property16":"value16",
    "Property17":"value17",
    "Property18":"value18",
    "Property19":value19,
    "Property20":value20,
    "Property21":value21
    }
    ]
    }
    },
    },

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited December 2022

    Please describe how you want the data displayed. The Data docs document the supported data structures. You might need to rearrange the data for Datatables to use.

    Maybe put together a simple test case with a sample of your data.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • schinamanagondaschinamanagonda Posts: 38Questions: 5Answers: 0
    edited December 2022

    http://live.datatables.net/riwirubo/2 finally found how to do test case. This is the way i want the data to be displayed without any buttons

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    The problem with the test case is you need to have a td for each column. See the HTML requirements for more details. Updated example:
    http://live.datatables.net/riwirubo/3/edit

    Datatables expects an array of row data. Your data is not an array of objects but just an object with nested objects. See this Nested objects example. Click the Ajax tab to see the data structure. Not sure you are looking for this though.

    See this example:
    http://live.datatables.net/juwonewo/1/edit

    I think this is what you are after. It shows one way you will need to restructure your data to work.

    Kevin

Sign In or Register to comment.