RIAS
asked on
Autoincrementing column in datatable
Hi,
How do I add a autonumber column to the datatable.
example:
Id ColName
1 abc
2 gfg
3 grg
4 ggg
ID should be autoincrementing column.
Thanks
How do I add a autonumber column to the datatable.
example:
Id ColName
1 abc
2 gfg
3 grg
4 ggg
ID should be autoincrementing column.
Thanks
Well, I would add a auto increment or identity column the table.
Hi,
What database or ORM?
Thanks,
Darren
What database or ORM?
Thanks,
Darren
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are using SQL server, you can define the column as an identity column, read
https://www.w3schools.com/sql/sql_autoincrement.asp
If you are using Oracle, you can define one sequence for such purpose.
https://www.w3schools.com/sql/sql_autoincrement.asp
If you are using Oracle, you can define one sequence for such purpose.
Hi,
Datatables have this https://datatables.net/examples/api/counter_columns.html
You need empty
Then this is the way to use it
or if you use
Datatables have this https://datatables.net/examples/api/counter_columns.html
You need empty
<th></th> <td></td>
for that columnThen this is the way to use it
$(document).ready(function() {
var t = $('#example').DataTable( {
"columnDefs": [ {
"searchable": false,
"orderable": false,
"targets": 0
} ],
"order": [[ 1, 'asc' ]]
} );
t.on( 'order.dt search.dt', function () {
t.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).draw();
} );
or if you use
"deferRender": true
$(document).ready(function() {
var t = $('#example').DataTable( {
"columnDefs": [ {
"searchable": false,
"orderable": false,
"targets": 0
} ],
"order": [[ 1, 'asc' ]]
} );
t.on( 'draw.dt', function () {
var PageInfo = $('#example').DataTable().page.info();
t.column(0, { page: 'current' }).nodes().each( function (cell, i) {
cell.innerHTML = i + 1 + PageInfo.start;
} );
} );
} );
ASKER
Thanks