欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

bootstrap table之通用方法( 时间控件,导出,动态下拉框, 表单验证 ,选中与获取信息)代码分享

程序员文章站 2023-09-08 15:13:35
1.bootstrap-table 单击单行选中 $('#gzrwtable').on('click-row.bs.table', function(e, row...

1.bootstrap-table 单击单行选中

$('#gzrwtable').on('click-row.bs.table', function(e, row, $element) {
$('.success').removeclass('success');// 清除前一次操作已选中行的选中状态
$($element).addclass('success');// 选中行添加选中状态
});

2.bootstrap-table 获取选中行信息

function getselectedrow() {
var index = $('#gzrwtable').find('tr.success').data('index');
return $('#gzrwtable').bootstraptable('getdata')[index];
}

3.时间控件 填写默认当前时间信息

var date = new date();
var mon = date.getmonth() + 1;
var day = date.getdate();
var nowday = date.getfullyear() + "-"
+ (mon < 10 ? "0" + mon : mon) + "-"
+ (day < 10 ? "0" + day : day);
$("#endtime").val(nowday);

4.bootstrap-table 验证表单信息 根据name值

function checkform(formid) {
$(formid).bootstrapvalidator({
message : 'this value is not valid',
feedbackicons : {
valid : 'glyphicon glyphicon-ok',
invalid : 'glyphicon glyphicon-remove',
validating : 'glyphicon glyphicon-refresh'
},
fields : {
task : {
group : '.col-sm-10',// 对应前台input的class占用宽度
validators : {
notempty : {
message : '请填任务内容!'
}
}
},
tel : {
group : '.col-sm-4',// 对应前台input的class占用宽度
validators : {
notempty : {
message : '请填写电话!'
},
phone : {
country : "cn",
message : '电话号码格式错误'
}
}
},
area : {
group : '.col-sm-4',// 对应前台input的class占用宽度
validators : {
numeric : {
message : '请填写数字!'
}
}
},
endtime : {
group : '.col-sm-4',// 对应前台input的class占用宽度
validators : {
notempty : {
message : '请选择截止日期!'
}
}
},
}
});
}
// 获取表单验证数据
var bootstrapvalidator = $("#addtaskform").data('bootstrapvalidator');
// 验证表单
bootstrapvalidator.validate();
// 判断是否全部验证通过 为通过重新验证,通过执行ajax
if (!bootstrapvalidator.isvalid()) {
return;
}

5.动态加载下拉框的内容 多选 单选都一样

function setuser() {
$("#receiver")[0].options.length = 0;
$.ajax({
type : 'post',
url : $.el.register.appurl + "gzrw/selectuser",
datatype : 'json',
success : function(data) {
$("#receiver")[0].options.add(new option('请选择', ''));
for (var i = 0; i < data.length; i++) {
$("#receiver")[0].options.add(new option(data[i].name,
data[i].id));
}
// 下拉框内容刷新
$("#receiver").selectpicker('refresh');
},
error : function(e) {
}
});
}

6.导出事件

$("#btnexport").click(function() {
var tablenum = $("#sgnqtable thead tr th").length;
$("#sgnqtable").tableexport({
type : 'excel', // 'csv', 'txt', 'sql', 'json', 'xml', 'excel',
// 'doc', 'png' or 'pdf'
filename : '表名',
escape : 'false',
ignorecolumn : [ tablenum - 1, tablenum - 4 ],// 不导出的列
});
});

面给大家分享bootstrapt-table 大量字段整体表单上传之时间处理

js 中用$('#adduserform').serialize(),//获取表单中所有数据 传送到前台 (controller)

$.ajax({ type : "post",

 url : $.el.register.appurl + "path",

data :$('#adduserform').serialize(),//获取表单中所有数据

datatype : 'json',

async : false,

success : function(msg) { },

error : function(error) { } });

这时如果表单中有时间类型 因为传过来的都是字符串类型 所以前台(实体)的时间类型接不到

 解决方法:

(1)可在entity 实体里字段上加@datetimeformat(pattern = "yyyy-mm-dd")

(2) 在controller中用个string接这个变量(不能和字段名重名) 转化为时间类型 再用 就可以了

public string addtask(user user(实体对象),
string datestr(用于接时间)) 
{ 
simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); 
parseposition pos = new parseposition(0); 
date date = sdf.parse(datestr,pos); 
gzrw.setendtime(date);//将时间加入实体 

}

以上所述是小编给大家介绍的bootstrop table之通用方法( 时间控件,导出,动态下拉框, 表单验证 ,选中与获取信息)代码分享,希望对大家有所帮助