概述
项目上使用guns框架,集成了BootStrapTable,但由于对框架不是很了解,导致有些问题解决起来比较费力
- 1.table结构发生变化,需要对table进行重新加载,而不是单纯的刷新。
- 2.服务端分页,我这里只探讨关于guns里的服务端分页,但如果封装的形式差不多的话,数据结构应该是不会发生大的变化
- 3.鼠标放到table上某个菜单时,有的表格内容显示不全,造成内容丢失,这个看了很多,但是有的局限性很大,或者是需要每个页面都加一遍方法,或者是刷新页面后,鼠标移上的事件就消失了。
前言
由于是使用guns框架,在写table时,都会使用guns 已经封装好的bootStrap方法 直接进行初始化,这里先贴出他的组件 可能有差异,但基本一致,使用的是老版本v1.11.1的bootstrap-table.min.js
(function () {
var BSTable = function (bstableId, url, columns) {
this.btInstance = null; //jquery和bootstrapTreeTable绑定的对象
this.bstableId = bstableId;
this.url =url;
this.method = "post";
this.paginationType="server";//使用服务器分页
this.columns = columns;
this.data = {
};// ajax的参数
this.toolbarId = bstableId + "Toolbar";
this.height = 665; //默认表格高度665
};
BSTable.prototype = {
/**
* 初始化bootstrap table
*/
init: function () {
var tableId = this.bstableId;
this.btInstance =
$('#'+tableId).bootstrapTable({
contentType:"application/x-www-form-urlencoded",
method: this.method, //请求数据的ajax类型
url: this.url, //请求数据的ajax的url
ajaxOptions:{
data: this.data, //请求数据的ajax的data属性
},
striped: true, //是否行间隔色
columns: this.columns, //列数组
toolbar: "#" + this.toolbarId,//顶部工具条
sortable:true,
sortOrder:"desc"