使用
$("#tableId").dataTable({
//建立动态表格table
"bProcessing": true,//进度条 "bDestroy": true, "bPaginate": true,//翻页功能 "bAutoWidth": false,//自动宽度 "bInfo": true,//页脚信息 "bFilter": false,//过滤功能 "bLengthChange": false,//不允许用户改变分页大小 "bServerSide": true, "oLanguage": { "sLengthMenu": "每页显示 _MENU_ 条记录", "sZeroRecords": "对不起,没有匹配的数据", "sInfo": "第 _START_ - _END_ 条 / 共 _TOTAL_ 条数据", "sInfoEmpty": "没有匹配的数据", "sInfoFiltered": "(数据表中共 _MAX_ 条记录)", "sProcessing": "正在加载中...", "oPaginate": { "sFirst": "第一页", "sPrevious": " 上一页 ", "sNext": " 下一页 ", "sLast": " 最后一页 " } }, "sServerMethod": "POST", "sAjaxSource": "${ctx}" + "/returnGoods/getBranchProduct.html", "fnServerParams": function (aoData) { aoData.push( { "name": "pname", "value": $("#goodsName").val() }, { "name": "branchid", "value": $("#branchidsel").val() }, { "name": "pid", "value": $("#goodsId").val() } ); }, "aoColumns": [ { "sTitle": "商品id", "mData": "HMP_Id", "sWidth": "300px", "bSortable": false, "bVisible": true }, { "sTitle": "商品名称", "mData": "HMP_Name", "sWidth": "300px", "bSortable": false, "bVisible": true }, { "sTitle": "规格", "mData": "BP_SellNorms", "sWidth": "300px", "bSortable": false, "bVisible": true }, { "sTitle": "参考单位", "mData": "BP_SellUnit", "sWidth": "300px", "bSortable": false, "bVisible": true }, { "sTitle": "参考装箱数", "mData": "HMP_BoxNum", "sWidth": "300px", "bSortable": false, "bVisible": true }, { "sTitle": "参考单价", "mData": "HMP_Price", "sWidth": "300px", "bSortable": false, "bVisible": true }, { "sTitle": "操作", "mData": "HMP_Id", "sWidth": "300px", "bSortable": false, "bVisible": true, "mRender": function (sVal, type, oObj) {//window.productMap[oObj.HMP_Id]={data:oObj}; 例子:②var html ="<button class='btn btn-xs btn-info' onclick = 'addProToForm(" + sVal + ",this);'><i class='icon-ok bigger-120'></i>添加</button>" return html; }, }]
});
function addProToForm(id,obj){
//例子:③
var data=window.productMap[id].data;
//例子:④
data.对应的字段名称
例如:
var HMP_Id=data.HMP_Id;
//如果此处需要获取,一整行的数据
1.首先要建立一个map ,这个map是一加载页面的时候就创建的好的一个空的Map集合 例子:①
2.将所需要的信息obj放进这个集合的指定位置 例子:②
3.获取集合中的一整行数据的信息例子③
4.获取需要的字段信息 例子:④
}
----------------------------------------
加载页面
<script type="text/javascript"> $(function () { //创建空的集合 :① window.productMap = {};