How to put index column in DataTable ?
How to put index column in DataTable ?
![headshot9x](https://secure.gravatar.com/avatar/54589dfd3263a2292883dab6c31c9a76/?default=https%3A%2F%2Fvanillicon.com%2F54589dfd3263a2292883dab6c31c9a76_200.png&rating=g&size=120)
Hello guys , I started with Datatable . I see at https://datatables.net/examples/api/counter_columns.html , as see it add one column with index to Datatable. I using data JSON in Datatable .Normal , I can load data from JSON to Datatable , but in here i just load data with number of column .
<table id="div_table" class="display cell-border compact" width="100%">
<thead>
<tr>
<td>Name</td>
<td>Des</td>
</tr>
</thead>
</table>
And my script
var table= $('#div_table').DataTable({
"processing": false,
"serverSide": false,
"ajax": {
.............
},
"aoColumns": [
{ "mData": "LOCATION_NAME" },
{ "mData": "LOCATION_DES" }
]
})
But trust in my JSON string have some orther data
{"d":"[{\"LOCATION_ID\":\"L0001\",\"AREA_ID\":\"A0001\",\"LOCATION_NAME\":\"Ninh Bình\",\"LOCATION_DES\":\"NB\",\"EDIT_DATE\":\"2014-11-05T00:00:00\",\"EDIT_BY\":\"user 1\",\"FLAG\":true,\"AREA\":null,\"TOPICs\":[],\"USERS_PROFILE\":[]}]"}
And now, I want
1) put a column with index for Datatable
2) get full data (or some columns) of row when click at a row
I apologize i want my table have two columns as same above and one column in first :
No Name Des
1 abc 234
2 edf 567
Thank you
This question has an accepted answers - jump to answer
Answers
I have encountered the same questions that when the table has hidden row,datatable will not work and an error like "oCols is not found..." ocurs
Ahm... I pass 2 hour try with index column and i have code above
As JSON string
In my page Test.aspx , I have eight columns.
Ok , this is my script
As it is ok , but when i click a row in table , it show "undefined undefined".
Can you tell me what is going on in here and i can fix it ? .Thank you so much .
Dear guys.
Ahm, about two hour`s ,i try and get something.I can hide column and create index column in DataTable. Ok, my JSON string as same
I change more columns in page Test.aspx , full columns in table as 7 columns
and this is my script
And after click a row , i get info " undefined and undefined" .
Can you tell me about it and give me some advice ?. Thank you
Dear guys.
Ahm, about two hour`s ,i try and get something.I can hide column and create index column in DataTable. Ok, my JSON string as same
I change more columns in page Test.aspx , full columns in table as 7 columns
and this is my script
And after click a row , i get info " undefined and undefined" .
Can you tell me about it and give me some advice ?. Thank you
Dear guys.
Ahm, about two hour`s ,i try and get something.I can hide column and create index column in DataTable. Ok, my JSON string as same
I change more columns in page Test.aspx , full columns in table as 7 columns
and this is my script
And after click a row , i get info " undefined and undefined" .
Can you tell me about it and give me some advice ?. Thank you