【发布时间】:2014-10-24 14:08:11
【问题描述】:
我正在使用 Datatables,并且能够编辑简单数据(即名称等),一切都很好,我试图了解我如何让它拥有一个 DateTime Picker 和 SELECT OPTION。
我有 2 个列要编辑,我说一个是 DateTime,另一个是我想添加一个 SELECT 选项。
到目前为止,这是我的代码,当通过 datatables-editable 阅读它们时,我不太清楚如何实现这一点,尤其是当我的 Editable.js 看起来不像他们的时。
您能否给我一些建议,告诉我如何将它们都添加进去,以便我的最终用户更容易更新信息。
var oTable = $('#tobebookedtable').dataTable();
oTable.$('td').editable( '../../../includes/planning/plg_tobebooked_edit.php', {
tooltip: 'Click to edit...',
"callback": function(sValue, y) {
var aPos = oTable.fnGetPosition(this);
oTable.fnUpdate(sValue, aPos[0], aPos[1]);
},
"submitdata": function (value, settings) {
return {
"row_id": this.getAttribute('id'),
"column": oTable.fnGetPosition(this)[2]
};
},
"height": "26px",
"width": "100%"
});
我尝试在 "width": "100%" 之后使用测试 SELECT 但这只是在您单击编辑时出现在每一列中
type : 'select',
style : 'display: inline',
data : "{'A':'Test A','B':'Test B','C':'Test C'}"
我的桌子
<table class="table table-striped table-hover table-bordered" id="tobebookedtable">
<thead>
<tr>
<th>Address</th>
<th>Postcode</th>
<th>Planned</th>
<th>TimeSlot</th>
<th>ByWho</th>
</tr>
</thead>
<tbody>
<?php
$plg = db::getInstance()->query('CALL sp_tobebooked()');
foreach ($plg->results() as $plg) {
?>
<tr id="<?php echo $plg->ID; ?>">
<td><?php echo $plg->Address; ?></td>
<td><?php echo $plg->Postcode; ?></td>
<td id="<?php echo $plg->ID; ?>"><?php echo $plg->Planned; ?></td>
<td id="<?php echo $plg->ID; ?>"><?php echo $plg->TimeSlot; ?></td>
<td id="<?php echo $plg->ID; ?>"><?php echo $plg->ByWho; ?></td>
</tr>
<?php }; ?>
</tbody>
</table>
TCHdvlp 建议中的测试示例
$('#tobebookedtable').dataTable( {
//for each generated row
"createdRow": function( row, data, dataIndex ) {
//create the dropdown
var myDropDown = $('<select><option value=""></option><option value="Yes">Yes</option><option value="No">No</option></select>');
//bind this dropdown with the JS object used by dataTable
myDropDown.on("change",function(){
data.ByWho = $(this).val();
});
//inject this dropdown in the desired column
$(row).find("td:eq("+data.ByWho+")").html(myDropDown);
}
});
【问题讨论】: