Javascript Jquery Datatables:单击一列中的按钮时如何获取row.data?
[![enter image description here][1][1]我有一个嵌套的表,我想通过post方法(类似于info.php?user=data[0]&key2=data)在每一行的一列中生成info.php的行数据, 我有一个按钮,但我需要一个按钮,并在单击按钮获取行数据时执行一些MySql。 当单击按钮时,将获取行中的每列数据,并将这些数据发布到info.php并在弹出窗口中查看 如何使用按钮将嵌套数据表中的行数据发布到其他php 点击按钮,是否无法获取行数据Javascript Jquery Datatables:单击一列中的按钮时如何获取row.data?,javascript,php,jquery,datatable,Javascript,Php,Jquery,Datatable,[![enter image description here][1][1]我有一个嵌套的表,我想通过post方法(类似于info.php?user=data[0]&key2=data)在每一行的一列中生成info.php的行数据, 我有一个按钮,但我需要一个按钮,并在单击按钮获取行数据时执行一些MySql。 当单击按钮时,将获取行中的每列数据,并将这些数据发布到info.php并在弹出窗口中查看 如何使用按钮将嵌套数据表中的行数据发布到其他php 点击按钮,是否无法获取行数据 $('#exa
$('#example tbody').on( 'click', 'button', function () {
var index = $(this).closest('tr').index();
var data = table.row( $(this).parents('tr') ).data();
alert("References is "+ data[0] +"and section is "+ data[ 1 ]+ " and Stature Titles is "+data[2] );
} );
-已更新只需为button class='button-info'添加类
columns:[
{ data:'name' },
{ data:'position' },
{ data:'salary' },
{
"targets": -1,
"data": null,
"defaultContent": "<button class='button-info'>Click Me!</button>"
}
]
然后为该按钮的click事件添加新事件,并获取父tr索引
只需使用上面添加的数据属性“index”获取所选父行的索引
var parent = $(this).closest('table').parents('tr').index();
var parentIndex = $('tbody tr:nth-child('+(parent)+')').attr('index');
并获取嵌套数据中的当前行
var index = $(this).closest('tr').index();
所以这是决赛
$('table').on( 'click', 'td .button-info', function () {
var parent = $(this).closest('table').parents('tr').index();
var parentIndex = $('tbody tr:nth-child('+(parent)+')').attr('index');
var currentIndex = $(this).closest('tr').index();
var data = sections[parentIndex][currentIndex];
console.log(data);
return;
window.open("/info.php?name=" + data.name + "&sal=" + data.salary);
} );
查看此更新的-updated只需为button class='button-info'添加类
columns:[
{ data:'name' },
{ data:'position' },
{ data:'salary' },
{
"targets": -1,
"data": null,
"defaultContent": "<button class='button-info'>Click Me!</button>"
}
]
然后为该按钮的click事件添加新事件,并获取父tr索引
只需使用上面添加的数据属性“index”获取所选父行的索引
var parent = $(this).closest('table').parents('tr').index();
var parentIndex = $('tbody tr:nth-child('+(parent)+')').attr('index');
并获取嵌套数据中的当前行
var index = $(this).closest('tr').index();
所以这是决赛
$('table').on( 'click', 'td .button-info', function () {
var parent = $(this).closest('table').parents('tr').index();
var parentIndex = $('tbody tr:nth-child('+(parent)+')').attr('index');
var currentIndex = $(this).closest('tr').index();
var data = sections[parentIndex][currentIndex];
console.log(data);
return;
window.open("/info.php?name=" + data.name + "&sal=" + data.salary);
} );
看到这个更新了吗是的。如果你能发布你的html以及你迄今为止所做的尝试,那就太好了:)我已经添加了部分代码耶。如果你能发布你的html和你迄今为止尝试过的东西,那将是非常好的:)我已经添加了我的代码的一部分Hi Newbee Dev,从你的代码中,它得到的是父数据而不是嵌套的datatable数据,我想得到嵌套的datatable数据而不是父数据,我已经更新了我的代码,但仍然无法工作,你能帮我如何修复吗?啊,好的。我的mistake@user6556472现在可以检查了是的,警报数据是我所知道的,但是当点击按钮时,如何将这些数据发布到弹出的info.php,比如info.php?name=data.name&sal=data.salary?@user6556472你想重定向到那个页面吗?嗨,新手开发人员,从你的代码中,它得到的是父数据,而不是嵌套的数据表数据,我想得到嵌套的datatable数据而不是父数据,我已经更新了我的代码,但仍然无法工作,你能帮我如何修复吗?啊,好的。我的mistake@user6556472现在可以检查了是的,警报数据是我所知道的,但是当单击按钮时,如何将这些数据发布到弹出的info.php,如info.php?name=data.name&sal=data.salary?@user6556472您想重定向到该页面吗?