How to access Nested Object Data (Data Orthogonal) Data with . and 0 notation in jQuery Datatables

How to access Nested Object Data (Data Orthogonal) Data with . and 0 notation in jQuery Datatables

shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

I'm referring Nested object data (objects) and Orthogonal Data to display following type of Complex Data(Java Object) in datatable.

How to access Nested Object Data (Orthogonal Data) with . and 0 notation in jQuery Datatables ?

I want to display

Sr. No. | Module Name | Category | Priority | Status | Requirement | Reference |

Module Name is from parent array
While other from Nested array (i.e.srsRequirementDetails)

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    Maybe this discussion from yesterday will help?
    https://datatables.net/forums/discussion/comment/125376

    Kevin

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    could you point me to the answer ?

    Thank you

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    Sorry, the thread din't help.

    Are you interested in only displaying the first element of srsRequirementDetails for each row?

    If so you can do something like this:

      columns: [
      {data: 'id'},
      {data: 'srsModuleName'},
      {data: 'srsRequirementDetails.0.categoryName'},
      {data: 'srsRequirementDetails.0.priorityName'},
      {data: 'srsRequirementDetails.0.statusName'},
      {data: 'srsRequirementDetails.0.requirement'},
      {data: 'srsRequirementDetails.0.reference'},
    
    ]
    

    Kevin

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    I already tried this, but this only display first array element, or more specific indexed array element.
    But I want to display (Iterate) all nested array elements.

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946

    As far as I know there is no provision to iterate an object and create new rows, using the above example. Each row is expected to be in its own array element. Can your server script return the data this way? You could then use Row Grouping to group the "modules".

    However you should be able to display array elements in one row using columns.render or you can use the Detailed Rows functionality if you want to hide/show the details.

    How do you want the details displayed, ie, one table row for all details or individual table rows for each detail?

    Kevin

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    @Kevin I want to Display one table row for all details, but this what I'm not able to achieve using columns.render , Detailed Rows is not my case.

    If not possible then I will change My server side script data return policy and then Use Row Grouping to group the "modules".

    Thank you.

  • kthorngrenkthorngren Posts: 21,301Questions: 26Answers: 4,946
    Answer ✓

    Here is a simple example of looping through a nested array of objects to build an output string using columns.render:
    http://live.datatables.net/kolomujo/1/edit

    Hope you can adapt it to your data and output requirements.

    Kevin

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    this is what I wanted to do. oops now again going to change script.
    thanks Kevin sir.

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    but what about to display rest fields on separate column

    columns: [
      {data: 'id'},
      {data: 'srsModuleName'},
      {data: 'srsRequirementDetails.0.categoryName'},
      {data: 'srsRequirementDetails.0.priorityName'},
      {data: 'srsRequirementDetails.0.statusName'},
      {data: 'srsRequirementDetails.0.requirement'},
      {data: 'srsRequirementDetails.0.reference'},
     
    ]
    
  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I'm afraid I don't understand the question. If you have other fields you want to display, either include them in another column as you have done those, or use columns.render as Kevin notes above to build a string.

    Allan

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    @allan can I use row span in Datatables ?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    You can't I'm afraid. DataTables does not support either rowspan or colspan in the table body.

    Allan

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    @allan I mean to ask you like Row Grouping uses colspan, is there any trick like rowspan ?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Nope - sorry.

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    Thank You Sir For Giving Me Your Valuable Time

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    @allan sir, can I use RowGrouping for above mention Nested Object data ?

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Sort of. You'd need to flatten your data source array into an array that has a single entry for each row to be shown in the DataTable.

    Allan

  • shantaram_tupeshantaram_tupe Posts: 11Questions: 1Answers: 0

    ok, I got it

This discussion has been closed.