$("#tableRole").bootstrapTable(‘destroy‘);
var table = $("#tableRole").bootstrapTable({
pagination: true,
useCurrentPage: true,
pageList : [10, 20, 50], // 记录数可选列表
pageSize : 10,
clickToSelect: true,
uniqueId: "roleId",
locale: ‘zh-cn‘,
data: data,
onClickRow: RoleRowClick,
//onDblClickRow: RoleDbRowClick,
toolbar: "#roleToolbar",
columns: [
{
title: ‘序号‘,
field: ‘seq‘,
align: ‘center‘,
valign: ‘middle‘,
//checkbox: true,
formatter: function(value, row, index) {
return index + 1;
}
},
{
title: ‘主键‘,
field: ‘roleId‘,
visible: false,
},
{
title: "角色名称",
field: "roleName",
align: "center",
class: "t-name"
},
{
title: "系统授权码",
field: "systemKey",
align: "center",
class: "t-key"
},
{
title: "创建时间",
field: "createTime",
align: "center",
class: "t-time"
},
{
title: "备注",
field: "remark",
align: "center",
class: "t-remark"
},
{
field: ‘operate‘,
title: ‘操作‘,
align: ‘center‘,
formatter: operateFormatter
}]
});
//$(".fixed-table-container").addClass("nano");
//$(".fixed-table-body").addClass("nano-content");
//setTimeout(function(){
calTableHeight();
$(‘.table‘).fixedHeaderTable();
//},0)
function operateFormatter(value, row, index) {
//selectedRow = row;
return [
‘<button type="button" class="eidt btn btn-default btn-sm" onclick="edit(\‘‘ + row.roleId + ‘\‘,‘+index+‘)" style="margin-right:15px;">编辑</button>‘,
‘<button type="button" class="delete btn btn-default btn-sm" onclick="removeRow(\‘‘ + row.roleId + ‘\‘)" style="margin-right:15px;">删除</button>‘,
‘<button type="button" class="btn btn-default" onclick="editRight(\‘‘ + row.roleId+‘\‘,\‘‘+ row.systemKey+ ‘\‘)" style="margin-right:15px;">配置权限</button>‘
].join(‘‘);
}
function RoleRowClick(row, $element, field)
{
//debugger
selectedRow = row;
}
转义字符\‘表示这个是单引号,是实际存在的单引号,不是拼接字符串而加上去的字符串。此处可以将row.roleId套一层\‘,将它强制转为字符串,不转也没有关系。js只能嵌套两层,所以最外层一般用单引号,里面用双引号,第三层就要使用转义字符了,但是据说在html里面不识别的,要用&quoat什么的。
这里开始在生成表格的时候就将row赋值给selectedRow,但是这样每一行表格生成的时候selectedRow一直在改变,最后将是最后一行的row值。还是需要使用行单击事件。
原文:http://www.cnblogs.com/1023linlin/p/6208609.html