效果图:
本文不是使用bootstrap-table-editable.js 拓展插件实现, 结合各个博客文章综合出的效果
html
js
function addRow() {
debugger
$('#dataTable').bootstrapTable('insertRow', {
index: 0,
row: {
'id': '',
'name': '',
'isCommon': '',
'relation': '',
'phone': '',
'idCard': '',
'content': '',
'operation': '',
'updateTime': ''
}
});
/* $('#subprocessTable').bootstrapTable('selectPage', 1); //Jump to the first page
var data = {actionId: '', actionName: '',category:'', description: ''}; //define a new row data,certainly it's empty
$('#subprocessTable').bootstrapTable('prepend', data); //the method of prepend must defined all fields,but append needn't
//$('#dataTable').bootstrapTable('append',data);
$("#dataTable tr:eq(1) td:eq(0)").trigger("dblclick");
$("#dataTable input")[0].focus();*/
}
$(function () {
$("#dataTable").bootstrapTable({
method: "GET",
url: CUR_PATH + "/riskOrder/queryCallRecord/" + $("#orderId").val(),
clickToSelect: true,
cache: false,
striped: true,
pagination: false,
pageSize: 10,
pageNumber: 1,
pageList: [10, 20, 30, 50],
search: false,
sidePagination: 'client',
silent: true,
singleSelect: true, // 单选checkbox
undefinedText: '',
columns: [
// {checkbox: true},
/*{field: 'id', title: '序号',edit:true,formatter:function(value, row, index){
return row.index=index+1 ; //返回行号
}},*/
{field: 'id', title: '序号', visible: false},
{field: 'name', title: '姓名', align: 'center'},
{field: 'isCommon', title: '是否共借人', align: 'center', formatter: isCommonSelect},
{field: 'relation', title: '与申请人关系', align: 'center', formatter: relationSelect},
{field: 'phone', title: '手机号', align: 'center'},
{field: 'idCard', title: '身份证号', align: 'center'},
{field: 'content', title: '电核记录', align: 'center'},
/* {field: 'operation', title: '操作',formatter:function(value,row,index){
var strHtml =''+
'';
return strHtml;
},edit:false},*/
{
field: 'operation',
title: '操作',
align: 'center',
formatter: actionFormatter
},
{field: 'updateTime', title: '操作时间', align: 'center'}
],
onDblClickCell: function (field, value, row, $element) {
if ("1" == row.type) {
if (field == 'content') {
let index = $element.parent().data('index');
if(isNotBlank(value)){
$element[0].innerHTML = "";
}else {
$element[0].innerHTML = "";
}
$("#inputCell").blur(function () {
var newValue = $("#inputCell").val();
row[field] = newValue;
$(this).remove();
$('#dataTable').bootstrapTable('updateCell', {
index: index,
field: field,
value: newValue
});
})
}
return;
}
$element.attr('contenteditable', true);
$element.blur(function () {
let index = $element.parent().data('index');
let tdValue = $element.html();
$("#dataTable").bootstrapTable('updateCell', {
index: index, //行索引
field: field, //列名
value: tdValue //cell值
})
})
}
});
});
function relationSelect(value, row, index) {
var strHtml = "";
$.ajax({
type: "GET",
dataType: "JSON",
async: false,
url: CUR_PATH + "/riskOrder/queryParam/",
success: function (result) {
strHtml += " ";
}
});
return strHtml
}
function relationSelectChange(value, lineIdx) {
// 判断哪个被选中
$('#dataTable').bootstrapTable('updateCell', {
index: lineIdx,
field: 'relation',
value: value
})
};
var isCommonSelect = function (value, row, index) {
var is_common_true = "";
var is_common_false = "";
var strHtml = "";
if (value === "1") {
is_common_true = 'selected';
} else if (value === "0") {
is_common_false = 'selected';
}
/* 1不可编辑 */
if ("1" == row.type) {
strHtml += "
包括行编辑回显 及下拉框实现 后端代码就省略了 很简单。
ps:一名爱打dota的小菜鸡