Column without construct
Column without construct
if have code:
var table = $('#example').DataTable( {
ajax: {
url: "url"
},
columns: [
{ data: "col" },
{ data: "users.last_name" },
{ data: "users.phone" },
],
select: true
} );
how i can write this withount construct?
i try :
var table = $('#example').DataTable();
table.ajax.url("https://api.myjson.com/bins/1d6rqo");
table.columns([{ data: 'col' },{ data: 'users.last_name' },{ data: 'users.phone' }]);
but it doesn't work..
This question has accepted answers - jump to:
Answers
Are you asking to dynamically build the options without using the passing them in the Datatables initialization?
There are some options you can change through the API like
ajax.url()
. There are many that you can't change like columns. They need to be set during initialization.What problem are you trying to solve?
Kevin
I am trying to add static row to the top of the table, and other data i try to load from json.How i can do this?
var table = $('#example').DataTable( {
ajax: {
url: "https://api.myjson.com/bins/1d6rqo"
},
columns: [
{ data: "col" },
{ data: "users.last_name" },
{ data: "users.phone" },
],
select: true
} );
var row = table.rows.add( [ {
"col": "Tiger Nixon",
"Last name": "System Architect",
"Phone #": "$3,120",
}, {
"col": "Garrett Winters",
"Last name": "Director",
"Phone #": "$5,300",
} ] )
.draw();
The Sorting with absolute positioned data blog discusses how to position specific rows to the top of the table.
Not sure I understand the question. When Datatables loads it will send an ajax request to the URL you specify and, assuming the JSON is the correct format, will load the data into the table. Is this working for you?
It doesn't look like the data structure you have for your
rows.add()
matches what you have defined in the Datatable. You have:But the structure you are adding is:
To match the Datatables config you would need this structure:
Kevin
I want to add new row at top of table.I want the new row to be the first in the table
var row = table.rows.add( [ {
"col": "Tiger Nixon",
"Last name": "System Architect",
"Phone #": "$3,120",
}, {
"col": "Garrett Winters",
"Last name": "Director",
"Phone #": "$5,300",
} ] )
.draw();
this code add row at bottom of the table, how i can move this row to top?
Did you read the Sorting with absolute positioned data doc I linked to? It explains how to do this.
Kevin