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();// 判斷是否全部驗證通過 為通過重新驗證,通過執行ajaxif (!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之通用方法( 時間控件,導出,動態下拉框, 表單驗證 ,選中與獲取信息)代碼分享,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答