I have two datasources, using them I need to create one datatable.

I have two datasources, using them I need to create one datatable.

shubhi03shubhi03 Posts: 4Questions: 3Answers: 0

Hi,I have two datasources ,Lets say A and B. And I need to create one datatable using them. Some of columns should come from A and other columns should come from B.
Is it possible to create single datatable using two datasource?

Answers

  • bcrouzybcrouzy Posts: 9Questions: 3Answers: 1

    I had the same problem with 3 datasources, the solution I found it's to create an html table as you want it to be, and create dataTable with this table. Perhaps it's not the better solution but it worked for me.

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49
    edited June 2016

    If you could merge you two datasources into a single JSON

    sourceData = [
      {
          A: {}
          B: {}
      },
      {
          A: {}
          B: {}
      },
      etc.
    ]
    

    I think you could then use data and columns.data as such

    .DataTable( {
        "data": sourceData,
        columns: [
           { 'data' : 'A.foo' },
           { 'data' : 'A.boo' },
           { 'data' : 'B.foo' },
           { 'data' : 'B.too' },
           { 'data' : 'A.moo' }
        ]
    } );
    

    Any additional formatting of the data would be accomplished using columns.render

This discussion has been closed.