In the second I want the datatable rows to be generated dynamically based on number of array elements.
The datatable expects the precise data structure, so can you please clarify the incoming data structure and the desired result? As far as I understood the use-case, you need to pre-format your data before passing it to the datatable.