Adding Button into the DataTable Row
Adding Button into the DataTable Row
vicky200456
Posts: 8Questions: 1Answers: 0
Hi everyone,
I use Datatable to present the Employee information ,and using the Bootstrap CSS framework
Format Such as:
[code]
IDNameAction
0001Peter
[/code]
It will have one button in each row
when i clicked the button, the Modals(as dialog) will be shown on the page. So user can edit the information by each employee .
i added this script and there haven't response.
[code]
oTable.$('tr').find('button').click(function() {
var data = oTable.fnGetData(this);
var id = data[0];
alert(id);
});
[/code]
what should i do?
Regards
Rick.
I use Datatable to present the Employee information ,and using the Bootstrap CSS framework
Format Such as:
[code]
IDNameAction
0001Peter
[/code]
It will have one button in each row
when i clicked the button, the Modals(as dialog) will be shown on the page. So user can edit the information by each employee .
i added this script and there haven't response.
[code]
oTable.$('tr').find('button').click(function() {
var data = oTable.fnGetData(this);
var id = data[0];
alert(id);
});
[/code]
what should i do?
Regards
Rick.
This discussion has been closed.
Replies
I use the fnDrawCallback option to apply event handlers to html elements that exist inside my table.
, "fnDrawCallback": function (oSettings) {
var $table = $(oSettings.nTable).dataTable();
$table.find("button").click(.........
Maybe this will work for you.
thanks for your information.
i rewirted the table structure as:
[code]
IDNameAction
0001Peter
[/code]
But, i have no idea how apply fnDrawCallback option to my situation.
i need to get the value of first cell in each row for query the specific employee. So i can present the correct detail in the dialog.
Your function isn't working because of this:
> oTable.fnGetData(this);
You are passing in the `button` element - which DataTables know nothing about. Try using:
[code]
oTable.fnGetData( $(this).closest('tr')[0] );
[/code]
Allan
Excellent!!Thanks for your solution.
Now i can get the correct value by clicked the button in each row
[code]
oTable.$('tr').find('button').click(function() {
var data = oTable.fnGetData($(this).closest('tr')[0]);
var id = data[0];//first cell
$('#empID').text(id);
});
[/code]
Rick