Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 在datatable的开头添加一列_Jquery_Json_Datatable - Fatal编程技术网

Jquery 在datatable的开头添加一列

Jquery 在datatable的开头添加一列,jquery,json,datatable,Jquery,Json,Datatable,大家好,我正在通过Json将我的行数据发送到我的datatable(用于html表显示的插件)我希望我的表有一个始终带有复选框的第一列,以下列是来自Jsonresponse的数据有没有办法使我的datatable具有此属性,或者我有一个可以转换Json响应的解决方案(具有行数据)多了一个字段,但如何将此新字段添加到Jsonresponse中。 提前感谢将是一个很大的帮助。不确定它在非常大的表上如何工作,但您可以尝试以下方法: $(table_selector thead tr).prepend(

大家好,我正在通过Json将我的行数据发送到我的datatable(用于html表显示的插件)我希望我的表有一个始终带有复选框的第一列,以下列是来自Jsonresponse的数据有没有办法使我的datatable具有此属性,或者我有一个可以转换Json响应的解决方案(具有行数据)多了一个字段,但如何将此新字段添加到Jsonresponse中。
提前感谢将是一个很大的帮助。

不确定它在非常大的表上如何工作,但您可以尝试以下方法:

$(table_selector thead tr).prepend(TH_WITH_HEADER);
$(table_selector tr).prepend(TD_WITH_CHECKBOX_IN_IT);
我并没有试着去看看它是否有效,但我想它应该有效

编辑
html:


临时雇员
临时雇员
JS:

var输入=$('');
$('.foo tr').prepend(输入);
$('.foo thead tr').prepend('checkbox header');

到目前为止,您有什么代码?您能创建一个JSFIDLE(或类似的)吗?你能举个例子吗?TD_和CHECKBOX_实际上是什么意思?如果这是一个愚蠢的问题,我很抱歉,我是jquery的新手。非常感谢,逻辑似乎太好了。但不确定这在我的senario中是否有效,我直接使用Datatables的aoData属性从JSON填充我的表。
<table class="foo">
<thead>
 <tr>
  <th></th>
  <th></th>
 </tr>
</thead>

<tbody>
 <tr>
  <td>temp</td>
  <td>temp</td>
 </tr>
</tbody>
</table>
var input = $('<td><input type="checkbox" class="bar"></td>');

$('.foo tr').prepend(input);
$('.foo thead tr').prepend('<th>checkbox header</th>');