set columns name
set columns name
marco.rudello@gmail.com
Posts: 12Questions: 4Answers: 0
Hi,
Its possible an example to set columns name by array?
eg: arcol = [colonna1,colonna2,colonna3.....,colonna4]
for (I=o;i < arcol.length;i++) { column.name = arcol[I]}
thanks
This question has accepted answers - jump to:
This discussion has been closed.
Answers
I'm afraid I don't really understand your question. The
columns.name
documentation contains an example showing how that property can be used.The column name is only useful for use with the
column()
selector method.Allan
Sorry for my English writing, I try to explain with example. In your doc if possible fill grid by this instruction:
$(document).ready(function() {
$('#example'String).DataTable( {
data: dataSet,
columns: [
{ title: "Name" },
{ title: "Position"},
{ title: "Office" },
{ title: "Extn."},
{ title: "Start date"},
{ title: "Salary"}
]
} );
} );
now in this case we kown how many columns and the columns name, but if I have array of data where the first row contains the columns name and the other row my data how declare the precedent instruction?
I hope you understand me....... sorry
Can you please paste what your array of data looks like. I think I follow you but need to be sure.
var ar1 = new Array(50);
ar1[0,0] = "NAME";
ar1[0,1] = "COGNOME";
ar1[0,2] = "DATA ASSUNZIONE";
ar1[0,3] = "DATA CESSAZIONE";
// do other
ar1[1,0] = "MARCO";
ar1[1,1] = "ROSSI";
ar1[1,2] = "01/06/2016";
ar1[1,3] = null;
// other ....
ar1[10,0] = "PAOLO";
ar1[10,1] = "FLINSTON"
ar1[10,2] = "01/05/2010";
ar1[10,3]= null;
now this bidimensional array contains on first row [0,x] name of columns and the other row data. How bind this array with datatable?
remember this array is dynamic and I don't know how many columns and data are there
be patience
thanks
Instead of a bi-dimensional array, could you make is as follows
Use ar1.headers to append necessary th elements to table.
Reason i bring it up like that is you could change your DataTable config to following
Yup - jr42.gordon's method is absolutely valid and a good option if you can modify the JSON format.
If you can't you'd need to preprocess the array using a
for
loop as you originally suggested in your code in the first post. Are you having difficultly doing that? If so, can you post the code you have tried so far.Allan
Hi Allan,
I you can send me example for array with using for loop
Thanks very match
Certainly - this would fall under the DataTables support options.
However, if you prefer to do it yourself, I would suggest you use
Array.prototype.shift()
to get the first "row" from your array and then use a trivialfor
loop like you have above that sets an object with aname
property.Allan