0

I have got a local JSON flat DataSource as shown below

var dataSet = [
    [
        "481.55",
        "10.40"

    ],
    [
        "561.30",
        "-2.55"

    ],
    [
        "368.20",
        "33.45"

    ]

];

And i am using Jquery Datatables to display Data in tabular format this way

 $(function()
  {

      $('#example').dataTable( {
        "data": dataSet,
        "columns": [
            { "title": "Price" },
            { "title": "Volume" }


        ]
    } );   

  })

This is my jsfiddle

http://jsfiddle.net/cv04pp37/9/

With this the data is shown in this way

**

Price   Volume
368.20  33.45
481.55  10.40
561.30  -2.55

**

I have got a javascript array as shown below where the first value refers to first value of the dataSet array and so on

var array_names =['ONE','TWO','THREE'];

My question is , Is it possible to display One more additional column Name in Jquery Datatables so that it looks like this

Name Price   Volume
ONE     368.20  33.45
TWO     481.55  10.40
THREE     561.30  -2.55

1 Answer 1

1

The jquery datatables doesn't support adding columns dynamically but there is a feasibility to hide/filter the column if you don't want it. As per my knowledge, this can be achieved in 2 ways

  1. Prepare the dataset(with 3 column values) and then initialize the datatable with the dataset.
  2. create a table with 3 column headers in the view and fill the table with content on page load or fill the datatable through the ajax call.
Sign up to request clarification or add additional context in comments.

3 Comments

I cannot go for the first Option as the dataset values will be returned from a backend server and i an't modify that . Could you please elaborate the second option a sample jsfiddle if you don't mind .
With this fiddle jsfiddle.net/cv04pp37/13 , i am always getting only the first value from the array
I have changed the dataSet a bit. this might help you. Fiddle here: jsfiddle.net/RajeshBoora/ktdj3u9r

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.