删除行
//监听工具条
table.on('tool(demo_fee)', function(obj){
var data = obj.data;
switch (obj.event)
{
case "delete":
layer.confirm('真的删除行么', function (index) {
fee_list = layui.table.cache['fee_list'];//获取缓存
var rowIndex = obj.tr.attr("data-index"); //获取行索引
for(var i=0;i<fee_list.length;i++){
if(fee_list[i].LAY_TABLE_INDEX == rowIndex){
fee_list.splice(i, 1);
}
}
//这里切记!!!!! 使用table.reload的方式更新
table.reload('fee_list',{
data:fee_list
});
layer.close(index);//关闭弹窗
});
break;
default:
break;
}
});
添加行同理
layer.open({
type: 2,
title: '添加',
area: ['50%', '70%'],
maxmin: true,
content: '<?=site_url("admin/Activity/fee_add")?>',
end:function(){
var add_id = localStorage.getItem('add_id');
var add_name = localStorage.getItem('add_name');
if(add_id && add_name){
localStorage.removeItem('add_name')
localStorage.removeItem('add_id')
fee_list = layui.table.cache['fee_list'];//获取缓存
var newRow = {
id:add_id,
name:add_name
};
fee_list.push(newRow);
table.reload('fee_list',{
data:fee_list
});
}
}
});