1.bootstrap-table 單擊單行選中
$('#gzrwTable').on('click-row.bs.table', function(e, row, $element) {$('.success').removeClass('success');// 清除前一次操作已選中行的選中狀態(tài)$($element).addClass('success');// 選中行添加選中狀態(tài)});2.bootstrap-table 獲取選中行信息
function getSelectedRow() {var index = $('#gzrwTable').find('tr.success').data('index');return $('#gzrwTable').bootstrapTable('getData')[index];}3.時(shí)間控件 填寫默認(rèn)當(dāng)前時(shí)間信息
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 驗(yàn)證表單信息 根據(jù)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',// 對(duì)應(yīng)前臺(tái)input的class占用寬度validators : {notEmpty : {message : '請(qǐng)?zhí)钊蝿?wù)內(nèi)容!'}}},tel : {group : '.col-sm-4',// 對(duì)應(yīng)前臺(tái)input的class占用寬度validators : {notEmpty : {message : '請(qǐng)?zhí)顚戨娫挘?},phone : {country : "CN",message : '電話號(hào)碼格式錯(cuò)誤'}}},area : {group : '.col-sm-4',// 對(duì)應(yīng)前臺(tái)input的class占用寬度validators : {numeric : {message : '請(qǐng)?zhí)顚憯?shù)字!'}}},endtime : {group : '.col-sm-4',// 對(duì)應(yīng)前臺(tái)input的class占用寬度validators : {notEmpty : {message : '請(qǐng)選擇截止日期!'}}},}});}// 獲取表單驗(yàn)證數(shù)據(jù)var bootstrapValidator = $("#addTaskForm").data('bootstrapValidator');// 驗(yàn)證表單bootstrapValidator.validate();// 判斷是否全部驗(yàn)證通過 為通過重新驗(yàn)證,通過執(zhí)行ajaxif (!bootstrapValidator.isValid()) {return;}5.動(dòng)態(tài)加載下拉框的內(nèi)容 多選 單選都一樣
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('請(qǐng)選擇', ''));for (var i = 0; i < data.length; i++) {$("#receiver")[0].options.add(new Option(data[i].name,data[i].id));}// 下拉框內(nèi)容刷新$("#receiver").selectpicker('refresh');},error : function(e) {}});}6.導(dǎo)出事件
$("#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 ],// 不導(dǎo)出的列});});下面給大家分享bootstrapt-table 大量字段整體表單上傳之時(shí)間處理
js 中用$('#addUserForm').serialize(),//獲取表單中所有數(shù)據(jù) 傳送到前臺(tái) (controller)
$.ajax({ type : "POST",
url : $.el.Register.AppUrl + "path",
data :$('#addUserForm').serialize(),//獲取表單中所有數(shù)據(jù)
dataType : 'json',
async : false,
success : function(msg) { },
error : function(error) { } });
這時(shí)如果表單中有時(shí)間類型 因?yàn)閭鬟^來的都是字符串類型 所以前臺(tái)(實(shí)體)的時(shí)間類型接不到
解決方法:
(1)可在entity 實(shí)體里字段上加@DateTimeFormat(pattern = "yyyy-MM-dd")
(2) 在controller中用個(gè)String接這個(gè)變量(不能和字段名重名) 轉(zhuǎn)化為時(shí)間類型 再用 就可以了
public String addTask(User user(實(shí)體對(duì)象),String dateStr(用于接時(shí)間)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); ParsePosition pos = new ParsePosition(0); Date date = sdf.parse(dateStr,pos); gzrw.setEndtime(date);//將時(shí)間加入實(shí)體 }
以上所述是小編給大家介紹的bootstrop table之通用方法( 時(shí)間控件,導(dǎo)出,動(dòng)態(tài)下拉框, 表單驗(yàn)證 ,選中與獲取信息)代碼分享,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注