How to correctly configure nested data?

How to correctly configure nested data?

eproziumeprozium Posts: 9Questions: 3Answers: 0

Hi,

How to correctly configure nested data?
E.g. in the example here: http://live.datatables.net/gekamiqi/1/edit
row 1 and 4 are rendered correctly , but not 2 or 3 (commented out since will break the table) :( .

Thank you.

Answers

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

    Either you need to pre-process the data so each row has the a.b.c object structure you defined in columns.data or you can use columns.render in the third column to appropriately display that column based on the existence of a.b.c by using the row parameter.

    Kevin

  • eproziumeprozium Posts: 9Questions: 3Answers: 0

    @kthorngren thank you for your help.

    Either you need to pre-process the data so each row has the a.b.c ..

    Whoaaa :# .This looks like a serious limitation: all serverside JSON serializers will simply render the data like in my example if values are null - nobody renders the entire null structure - because it's null, and it would be correct otherwise.

    or you can use columns.render in the third column ...

    That would require for almost each column to write renderer for display, filter and sort - even if those are normal values, otherwise correctly rendered by DataTables if they weren't nested :( .

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

    The point is if you are going to tell Datatables to look for an object a.b.c then that structure needs to be there. Can your server script not generate that structure for each row returned?

    Kevin

  • eproziumeprozium Posts: 9Questions: 3Answers: 0

    The point is if you are going to tell Datatables to look for an object a.b.c then that structure needs to be there.

    Thank you for the info. I understand that DataTables "expects" that, but compared to all other solutions I've seen, it's technically wrong: other code that relies on a===null would break if one would pass a:{b:{c:null}} instead.

    Can your server script not generate that structure for each row returned?

    One could, but than all other components in the page would break. Also it's not a default behavior on any JSON serializer library I know, so one would need to write extra code :).

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

    Maybe using defaultContent will help. Checkout this updated example:
    http://live.datatables.net/goqihidi/1/edit

    Kevin

  • eproziumeprozium Posts: 9Questions: 3Answers: 0

    Maybe using defaultContent will help

    Yeah, it does :) . Thanks for the hint.

    defaultContent: null does not seem to work, but defaultContent: '' seems to do it.

    Only CSV and Excel Export seems to be affected by this (but I can't make those buttons appear in the official JSBin in order to show it).

This discussion has been closed.