引用的css:

<link href="@Url.Content("~/Css/bootstrap.min.css")" rel="stylesheet" type="text/css" />

<link href="@Url.Content("~/Css/bootstrap-table.css")" rel="stylesheet" type="text/css" />

引用的JS:

<script src="../../Scripts/jquery.js" type="text/javascript"></script>

<script src="../../Scripts/bootstrap.min.js" type="text/javascript"></script>

<script src="../../Scripts/bootstrap-table.js" type="text/javascript"></script>

<script src="../../Scripts/bootstrap-table-zh-CN.js" type="text/javascript"></script>

常用方法:

刷新表格:$table.bootstrapTable('refresh');

获取选择的行:$table.bootstrapTable('getSelections');

1.服务端请求:即当数据量大,千百万条数据的情况下,只获取当页条件下的数据。每点击分页或查询都向服务端重新获取分页数据。

前端代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
function initTable() {
 
            var queryUrl = '@Url.Content("~/Welcome/QueryList")' '?rnd=' + +Math.random();
 
            $table = $('#table-javascript').bootstrapTable({
 
                method: 'get',
 
                url: queryUrl,
 
                height: $(window).height() - 200,
 
                striped: true,
 
                pagination: true,
 
                singleSelect: false,
 
                pageSize: 50,
 
                pageList: [10, 50, 100, 200, 500],
 
                search: false//不显示 搜索框
 
                showColumns: false//不显示下拉框(选择显示的列)
 
                sidePagination: "server"//服务端请求
 
                queryParams: queryParams,
 
                minimunCountColumns: 2,
 
                columns: [{
 
                    field: 'state',
 
                    checkbox: true
 
                }, {
 
                    field: 'Name',
 
                    title: '姓名',
 
                    width: 100,
 
                    align: 'center',
 
                    valign: 'middle',
 
                    sortable: true,
 
                    formatter: nameFormatter
 
                }, {
 
                    field: 'Gender',
 
                    title: '性别',
 
                    width: 40,
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true,
 
                    formatter: sexFormatter,
 
                    sorter: priceSorter
 
                }, {
 
                    field: 'Birthday',
 
                    title: '出生日期',
 
                    width: 80,
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'CtfId',
 
                    title: '身份证',
 
                    width: 80,
 
                    align: 'middle',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'Address',
 
                    title: '地址',
 
                    width: 180,
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'Tel',
 
                    title: '固定电话',
 
                    width: 100,
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'Mobile',
 
                    title: '手机号码',
 
                    width: 100,
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'operate',
 
                    title: '操作',
 
                    width: 100,
 
                    align: 'center',
 
                    valign: 'middle',
 
                    formatter: operateFormatter,
 
                    events: operateEvents
 
                }],
 
                onLoadSuccess:function(){
 
  
 
                },
 
                onLoadError: function () {
 
                    mif.showErrorMessageBox("数据加载失败!");
 
                }
 
            });
 
        }
 
//传递的参数
 
function queryParams(params) {
 
            return {
 
                pageSize: params.pageSize,
 
                pageIndex: params.pageNumber,
 
                UserName: $("#txtName").val(),
 
                Birthday: $("#txtBirthday").val(),
 
                Gender: $("#Gender").val(),
 
                Address: $("#txtAddress").val(),
 
                name: params.sortName,
 
                order: params.sortOrder
 
            };
 
        }

  

服务器端代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
public ActionResult QueryList(int pageIndex = 1, int pageSize = 100)
 
        {
 
            try
 
            {
 
                string name = Request["UserName"];
 
                string birthday = Request["Birthday"];
 
                string gender = Request["Gender"];
 
                string Address = Request["Address"];
 
                Document docQuery = new Document();
 
                if (!string.IsNullOrEmpty(name))
 
                {
 
                    docQuery.Add("Name"new MongoRegex(".*" + name + ".*", MongoRegexOption.IgnoreCase));
 
                }
 
                if (!string.IsNullOrEmpty(birthday))
 
                {
 
                    docQuery.Add("Birthday"new MongoRegex(".*" + birthday + ".*", MongoRegexOption.IgnoreCase));
 
                }
 
                if (!string.IsNullOrEmpty(gender))
 
                {
 
                    docQuery.Add("Gender", gender);
 
                }
 
                if (!string.IsNullOrEmpty(Address))
 
                {
 
                    docQuery.Add("Address"new MongoRegex(".*" + Address + ".*", MongoRegexOption.IgnoreCase));
 
                }
 
                if (this.HttpContext.Request.QueryString.AllKeys.Contains("ToExcel"))
 
                {
 
                    List<OpenRoom> listExport = MongoDbHelper.GetList<OpenRoom>(MongoTables.OpenRoom, docQuery);
 
                    //List<string> listTilte = new List<string> { "" };
 
                    ExportMethod(listExport);
 
                }
 
                long totalCount = MongoDbHelper.GetTotalCount<OpenRoom>(MongoTables.OpenRoom, docQuery);
 
                var list = MongoDbHelper.GetList<OpenRoom>(MongoTables.OpenRoom, docQuery, new Document(), pageIndex, pageSize);
 
                string jsonString = JsonHelper.ObjToJson(list);
 
                jsonString = "{\"total\":" + totalCount.ToString() + ",\"rows\":" + jsonString + "}";
 
                return Content(jsonString);
 
            }
 
            catch (Exception ex)
 
            {
 
                return Content(ex.Message);
 
            }
 
  
 
        }

  

注意返回的格式:要返回总记录数total及分页后数据rows。

未解决问题:导出Excel时,超出65536行数据时,会异常。怎样解决这个问题?

2.客户端请求:当数据量较少,只有上千条数据时,一次性将所有数据返回给客户端,无论点下一页,或搜索条件时,不向服务端发请求,实现全文检索。

这个比较简单,将sidePagination属性设为 "client",因为客户端会处理分页和全文检索,无需向服务器端发请求,所以也无需传递参数。

前端JS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
function initTable() {
 
            var queryUrl = '@Url.Content("~/UserInfo/QueryList")' '?rnd=' + +Math.random();
 
            $table = $('#table-javascript').bootstrapTable({
 
                method: 'get',
 
                url: queryUrl,
 
                height: $(window).height() - 200,
 
                striped: true,
 
                pagination: true,
 
                pageSize: 50,
 
                pageList: [10, 25, 50, 100, 200],
 
                search: true,
 
                sidePagination: "client",
 
                showColumns: true,
 
                minimunCountColumns: 2,
 
                columns: [{
 
                    field: 'state',
 
                    radio: true
 
                }, {
 
                    field: 'Id',
 
                    title: 'ID',
 
                    align: 'right',
 
                    valign: 'bottom',
 
                    sortable: true
 
                }, {
 
                    field: 'UserName',
 
                    title: '姓名',
 
                    width: 100,
 
                    align: 'center',
 
                    valign: 'middle',
 
                    sortable: true,
 
                    formatter: nameFormatter
 
                }, {
 
                    field: 'Account',
 
                    title: '账号',
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'Address',
 
                    title: '家乡',
 
                    align: 'middle',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'Phone',
 
                    title: '电话',
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'QQ',
 
                    title: 'QQ号码',
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'Remark',
 
                    title: '备注',
 
                    align: 'left',
 
                    valign: 'top',
 
                    sortable: true
 
                }, {
 
                    field: 'operate',
 
                    title: '操作',
 
                    align: 'center',
 
                    width: 100,
 
                    valign: 'middle',
 
                    formatter: operateFormatter,
 
                    events: operateEvents
 
                }]
 
            });
 
        }

  

后台直接返回Json数据即可。

后台代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public ActionResult QueryList()
 
        {
 
            try
 
            {
 
                List<sys_user> list = accessHelper.GetUserList();
 
                string jsonString = JsonHelper.ObjToJson(list);
 
                return Content(jsonString);
 
            }
 
            catch (Exception ex)
 
            {
 
                return Content(ex.Message);
 
            }
 
  
 
        }

  

源码下载

BootstrapTable(附源码) Bootstrap结合BootstrapTable的使用,分为两种模试显示列表。的更多相关文章

  1. Bootstrap结合BootstrapTable的使用,分为两种模试显示列表。 自适应表格

    引用的css: <link href="@Url.Content("~/Css/bootstrap.min.css")" rel="styles ...

  2. Bootstrap列表与代码样式(附源码)--Bootstrap

    给大家分享下Bootstrap框架中列表与代码样式相关的知识 1.列表 (1)无序列表 <ul> <li>CN217编程</li> </ul> 注意:u ...

  3. Java基础进阶:学生管理系统数组方式分包源码实现,教师管理系统集合和数组两种方式源码实现,图书馆管理系统源码实现,现附重难点,代码实现源码,课堂笔记,课后扩展及答案

    1.案例驱动模式 1.1案例驱动模式概述 (理解) 通过我们已掌握的知识点,先实现一个案例,然后找出这个案例中,存在的一些问题,在通过新知识点解决问题 1.2案例驱动模式的好处 (理解) 解决重复代码 ...

  4. BootstrapTable(附源码)

    Bootstrap结合BootstrapTable的使用,分为两种模试显示列表. 引用的css: <link href="@Url.Content("~/Css/bootst ...

  5. 使用 SVG 制作单选和多选框动画【附源码】

    通过 JavaScript 实现 SVG 路径动画,我们可以做很多花哨的东西.今天我们要为您介绍一些复选框和单选按钮效果.实现的主要思路是隐藏原生的输入框,使用伪元素创造更具吸引力的样式,输入框被选中 ...

  6. 使用 CSS3 实现 3D 图片滑块效果【附源码下载】

    使用 CSS3 的3D变换特性,我们可以通过让元素在三维空间中变换来实现一些新奇的效果. 这篇文章分享的这款 jQuery 立体图片滑块插件,利用了 3D transforms(变换)属性来实现多种不 ...

  7. MVC系列——MVC源码学习:打造自己的MVC框架(二:附源码)

    前言:上篇介绍了下 MVC5 的核心原理,整篇文章比较偏理论,所以相对比较枯燥.今天就来根据上篇的理论一步一步进行实践,通过自己写的一个简易MVC框架逐步理解,相信通过这一篇的实践,你会对MVC有一个 ...

  8. C#进阶系列——一步一步封装自己的HtmlHelper组件:BootstrapHelper(三:附源码)

    前言:之前的两篇封装了一些基础的表单组件,这篇继续来封装几个基于bootstrap的其他组件.和上篇不同的是,这篇的有几个组件需要某些js文件的支持. 本文原创地址:http://www.cnblog ...

  9. 使用 CSS3 动感的图片标题动画效果【附源码下载】

    在网站中,有很多地方会需要在图片上显示图片标题.使用 CSS3 过渡和变换可以实现动感的鼠标悬停显示效果.没有使用 JavaScript,所以只能在支持 CSS3 动画的现代浏览器中才能正常工作.您可 ...

随机推荐

  1. opencart配置

    1.安装opencart 2.修改后台目录(慎重,修改后插件安装会出错) Opencart默认的后台是网站/admin这样子,很多人可以猜到这种组合对于正式生产环境很不安全,我们可以把这个admin改 ...

  2. Android中通过pid获取app包名

    String callerPackage = getAppNameByPID(getContext(), Binder.getCallingPid()); private String getAppN ...

  3. locks

    grep 'parking to wait for' gs2_jstack_141203.txt |  uniq -c | sort -n查看哪个锁出现次数最多 http://blog.csdn.ne ...

  4. pe and elf

    http://staff.ustc.edu.cn/~sycheng/sst/exp_crack/ELF.pdf https://refspecs.linuxbase.org/elf/TIS1.1.pd ...

  5. PAT (Advanced Level) 1013. Battle Over Cities (25)

    并查集判断连通性. #include<iostream> #include<cstring> #include<cmath> #include<algorit ...

  6. 卷积神经网络(CNN)新手指南 1

    http://blog.csdn.net/real_myth/article/details/52273930 卷积神经网络(CNN)新手指南 2016-07-29 18:22 Blake 1条评论 ...

  7. [iOS]C语言技术视频-05-程序循环结构(do{}while();)

    下载地址: 链接: http://pan.baidu.com/s/1c02ke3m 密码: x97w

  8. UWSGITOP-----监控uwsgi 性能

    启动 uwsgi -x etc/bfdds_cookiemapping_conf.xml --stats /tmp/stats.socket 查看 uwsgitop /tmp/stats.socket ...

  9. jQuery插件实现的方法和原理简单说明

    下文来自 http://www.itzhai.com/jquery-plug-ins-to-achieve-the-methods-and-principles-of-simple-instructi ...

  10. JSTL c标签,fn标签,fmt标签 - 生活在爪洼岛上 - ITeye技术网站

    jstl是sun定义的标准,由apache实现,所以要下载jar包的话去apache,要看api文档的话,去sun,API文档在此:http://java.sun.com/products/jsp/j ...