annotate bin/js/bootstrap-table.js @ 56:53be75cb8afd draft

Uploaded
author pierre.pouchin
date Thu, 13 Sep 2018 04:44:52 -0400
parents 4bc00caa60b4
children 9185ca0a7b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1 /**
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2 * @author zhixin wen <wenzhixin2010@gmail.com>
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3 * version: 1.11.1
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
4 * https://github.com/wenzhixin/bootstrap-table/
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
5 */
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
6
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
7 (function ($) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
8 'use strict';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
9
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
10 // TOOLS DEFINITION
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
11 // ======================
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
12
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
13 var cachedWidth = null;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
14
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
15 // it only does '%s', and return '' when arguments are undefined
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
16 var sprintf = function (str) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
17 var args = arguments,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
18 flag = true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
19 i = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
20
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
21 str = str.replace(/%s/g, function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
22 var arg = args[i++];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
23
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
24 if (typeof arg === 'undefined') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
25 flag = false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
26 return '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
27 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
28 return arg;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
29 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
30 return flag ? str : '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
31 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
32
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
33 var getPropertyFromOther = function (list, from, to, value) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
34 var result = '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
35 $.each(list, function (i, item) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
36 if (item[from] === value) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
37 result = item[to];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
38 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
39 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
40 return true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
41 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
42 return result;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
43 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
44
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
45 var getFieldIndex = function (columns, field) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
46 var index = -1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
47
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
48 $.each(columns, function (i, column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
49 if (column.field === field) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
50 index = i;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
51 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
52 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
53 return true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
54 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
55 return index;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
56 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
57
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
58 // http://jsfiddle.net/wenyi/47nz7ez9/3/
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
59 var setFieldIndex = function (columns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
60 var i, j, k,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
61 totalCol = 0,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
62 flag = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
63
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
64 for (i = 0; i < columns[0].length; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
65 totalCol += columns[0][i].colspan || 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
66 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
67
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
68 for (i = 0; i < columns.length; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
69 flag[i] = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
70 for (j = 0; j < totalCol; j++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
71 flag[i][j] = false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
72 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
73 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
74
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
75 for (i = 0; i < columns.length; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
76 for (j = 0; j < columns[i].length; j++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
77 var r = columns[i][j],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
78 rowspan = r.rowspan || 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
79 colspan = r.colspan || 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
80 index = $.inArray(false, flag[i]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
81
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
82 if (colspan === 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
83 r.fieldIndex = index;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
84 // when field is undefined, use index instead
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
85 if (typeof r.field === 'undefined') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
86 r.field = index;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
87 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
88 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
89
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
90 for (k = 0; k < rowspan; k++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
91 flag[i + k][index] = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
92 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
93 for (k = 0; k < colspan; k++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
94 flag[i][index + k] = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
95 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
96 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
97 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
98 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
99
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
100 var getScrollBarWidth = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
101 if (cachedWidth === null) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
102 var inner = $('<p/>').addClass('fixed-table-scroll-inner'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
103 outer = $('<div/>').addClass('fixed-table-scroll-outer'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
104 w1, w2;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
105
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
106 outer.append(inner);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
107 $('body').append(outer);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
108
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
109 w1 = inner[0].offsetWidth;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
110 outer.css('overflow', 'scroll');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
111 w2 = inner[0].offsetWidth;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
112
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
113 if (w1 === w2) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
114 w2 = outer[0].clientWidth;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
115 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
116
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
117 outer.remove();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
118 cachedWidth = w1 - w2;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
119 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
120 return cachedWidth;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
121 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
122
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
123 var calculateObjectValue = function (self, name, args, defaultValue) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
124 var func = name;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
125
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
126 if (typeof name === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
127 // support obj.func1.func2
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
128 var names = name.split('.');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
129
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
130 if (names.length > 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
131 func = window;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
132 $.each(names, function (i, f) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
133 func = func[f];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
134 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
135 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
136 func = window[name];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
137 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
138 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
139 if (typeof func === 'object') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
140 return func;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
141 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
142 if (typeof func === 'function') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
143 return func.apply(self, args || []);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
144 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
145 if (!func && typeof name === 'string' && sprintf.apply(this, [name].concat(args))) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
146 return sprintf.apply(this, [name].concat(args));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
147 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
148 return defaultValue;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
149 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
150
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
151 var compareObjects = function (objectA, objectB, compareLength) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
152 // Create arrays of property names
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
153 var objectAProperties = Object.getOwnPropertyNames(objectA),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
154 objectBProperties = Object.getOwnPropertyNames(objectB),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
155 propName = '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
156
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
157 if (compareLength) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
158 // If number of properties is different, objects are not equivalent
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
159 if (objectAProperties.length !== objectBProperties.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
160 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
161 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
162 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
163
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
164 for (var i = 0; i < objectAProperties.length; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
165 propName = objectAProperties[i];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
166
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
167 // If the property is not in the object B properties, continue with the next property
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
168 if ($.inArray(propName, objectBProperties) > -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
169 // If values of same property are not equal, objects are not equivalent
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
170 if (objectA[propName] !== objectB[propName]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
171 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
172 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
173 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
174 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
175
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
176 // If we made it this far, objects are considered equivalent
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
177 return true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
178 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
179
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
180 var escapeHTML = function (text) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
181 if (typeof text === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
182 return text
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
183 .replace(/&/g, '&amp;')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
184 .replace(/</g, '&lt;')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
185 .replace(/>/g, '&gt;')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
186 .replace(/"/g, '&quot;')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
187 .replace(/'/g, '&#039;')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
188 .replace(/`/g, '&#x60;');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
189 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
190 return text;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
191 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
192
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
193 var getRealDataAttr = function (dataAttr) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
194 for (var attr in dataAttr) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
195 var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
196 if (auxAttr !== attr) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
197 dataAttr[auxAttr] = dataAttr[attr];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
198 delete dataAttr[attr];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
199 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
200 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
201
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
202 return dataAttr;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
203 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
204
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
205 var getItemField = function (item, field, escape) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
206 var value = item;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
207
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
208 if (typeof field !== 'string' || item.hasOwnProperty(field)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
209 return escape ? escapeHTML(item[field]) : item[field];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
210 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
211 var props = field.split('.');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
212 for (var p in props) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
213 if (props.hasOwnProperty(p)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
214 value = value && value[props[p]];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
215 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
216 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
217 return escape ? escapeHTML(value) : value;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
218 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
219
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
220 var isIEBrowser = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
221 return !!(navigator.userAgent.indexOf("MSIE ") > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
222 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
223
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
224 var objectKeys = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
225 // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
226 if (!Object.keys) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
227 Object.keys = (function() {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
228 var hasOwnProperty = Object.prototype.hasOwnProperty,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
229 hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
230 dontEnums = [
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
231 'toString',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
232 'toLocaleString',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
233 'valueOf',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
234 'hasOwnProperty',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
235 'isPrototypeOf',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
236 'propertyIsEnumerable',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
237 'constructor'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
238 ],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
239 dontEnumsLength = dontEnums.length;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
240
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
241 return function(obj) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
242 if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
243 throw new TypeError('Object.keys called on non-object');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
244 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
245
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
246 var result = [], prop, i;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
247
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
248 for (prop in obj) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
249 if (hasOwnProperty.call(obj, prop)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
250 result.push(prop);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
251 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
252 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
253
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
254 if (hasDontEnumBug) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
255 for (i = 0; i < dontEnumsLength; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
256 if (hasOwnProperty.call(obj, dontEnums[i])) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
257 result.push(dontEnums[i]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
258 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
259 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
260 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
261 return result;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
262 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
263 }());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
264 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
265 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
266
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
267 // BOOTSTRAP TABLE CLASS DEFINITION
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
268 // ======================
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
269
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
270 var BootstrapTable = function (el, options) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
271 this.options = options;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
272 this.$el = $(el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
273 this.$el_ = this.$el.clone();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
274 this.timeoutId_ = 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
275 this.timeoutFooter_ = 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
276
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
277 this.init();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
278 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
279
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
280 BootstrapTable.DEFAULTS = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
281 classes: 'table table-hover',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
282 sortClass: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
283 locale: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
284 height: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
285 undefinedText: '-',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
286 sortName: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
287 sortOrder: 'asc',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
288 sortStable: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
289 striped: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
290 columns: [[]],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
291 data: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
292 totalField: 'total',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
293 dataField: 'rows',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
294 method: 'get',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
295 url: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
296 ajax: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
297 cache: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
298 contentType: 'application/json',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
299 dataType: 'json',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
300 ajaxOptions: {},
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
301 queryParams: function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
302 return params;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
303 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
304 queryParamsType: 'limit', // undefined
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
305 responseHandler: function (res) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
306 return res;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
307 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
308 pagination: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
309 onlyInfoPagination: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
310 paginationLoop: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
311 sidePagination: 'client', // client or server
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
312 totalRows: 0, // server side need to set
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
313 pageNumber: 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
314 pageSize: 10,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
315 pageList: [10, 25, 50, 100],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
316 paginationHAlign: 'right', //right, left
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
317 paginationVAlign: 'bottom', //bottom, top, both
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
318 paginationDetailHAlign: 'left', //right, left
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
319 paginationPreText: '&lsaquo;',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
320 paginationNextText: '&rsaquo;',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
321 search: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
322 searchOnEnterKey: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
323 strictSearch: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
324 searchAlign: 'right',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
325 selectItemName: 'btSelectItem',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
326 showHeader: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
327 showFooter: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
328 showColumns: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
329 showPaginationSwitch: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
330 showRefresh: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
331 showToggle: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
332 buttonsAlign: 'right',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
333 smartDisplay: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
334 escape: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
335 minimumCountColumns: 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
336 idField: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
337 uniqueId: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
338 cardView: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
339 detailView: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
340 detailFormatter: function (index, row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
341 return '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
342 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
343 trimOnSearch: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
344 clickToSelect: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
345 singleSelect: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
346 toolbar: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
347 toolbarAlign: 'left',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
348 checkboxHeader: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
349 sortable: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
350 silentSort: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
351 maintainSelected: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
352 searchTimeOut: 500,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
353 searchText: '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
354 iconSize: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
355 buttonsClass: 'default',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
356 iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
357 icons: {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
358 paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
359 paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
360 refresh: 'glyphicon-refresh icon-refresh',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
361 toggle: 'glyphicon-list-alt icon-list-alt',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
362 columns: 'glyphicon-th icon-th',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
363 detailOpen: 'glyphicon-plus icon-plus',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
364 detailClose: 'glyphicon-minus icon-minus'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
365 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
366
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
367 customSearch: $.noop,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
368
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
369 customSort: $.noop,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
370
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
371 rowStyle: function (row, index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
372 return {};
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
373 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
374
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
375 rowAttributes: function (row, index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
376 return {};
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
377 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
378
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
379 footerStyle: function (row, index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
380 return {};
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
381 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
382
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
383 onAll: function (name, args) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
384 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
385 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
386 onClickCell: function (field, value, row, $element) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
387 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
388 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
389 onDblClickCell: function (field, value, row, $element) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
390 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
391 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
392 onClickRow: function (item, $element) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
393 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
394 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
395 onDblClickRow: function (item, $element) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
396 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
397 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
398 onSort: function (name, order) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
399 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
400 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
401 onCheck: function (row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
402 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
403 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
404 onUncheck: function (row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
405 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
406 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
407 onCheckAll: function (rows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
408 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
409 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
410 onUncheckAll: function (rows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
411 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
412 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
413 onCheckSome: function (rows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
414 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
415 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
416 onUncheckSome: function (rows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
417 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
418 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
419 onLoadSuccess: function (data) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
420 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
421 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
422 onLoadError: function (status) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
423 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
424 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
425 onColumnSwitch: function (field, checked) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
426 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
427 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
428 onPageChange: function (number, size) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
429 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
430 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
431 onSearch: function (text) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
432 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
433 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
434 onToggle: function (cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
435 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
436 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
437 onPreBody: function (data) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
438 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
439 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
440 onPostBody: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
441 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
442 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
443 onPostHeader: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
444 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
445 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
446 onExpandRow: function (index, row, $detail) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
447 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
448 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
449 onCollapseRow: function (index, row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
450 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
451 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
452 onRefreshOptions: function (options) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
453 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
454 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
455 onRefresh: function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
456 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
457 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
458 onResetView: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
459 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
460 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
461 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
462
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
463 BootstrapTable.LOCALES = {};
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
464
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
465 BootstrapTable.LOCALES['en-US'] = BootstrapTable.LOCALES.en = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
466 formatLoadingMessage: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
467 return 'Loading, please wait...';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
468 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
469 formatRecordsPerPage: function (pageNumber) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
470 return sprintf('%s rows per page', pageNumber);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
471 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
472 formatShowingRows: function (pageFrom, pageTo, totalRows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
473 return sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
474 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
475 formatDetailPagination: function (totalRows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
476 return sprintf('Showing %s rows', totalRows);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
477 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
478 formatSearch: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
479 return 'Search';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
480 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
481 formatNoMatches: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
482 return 'No matching records found';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
483 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
484 formatPaginationSwitch: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
485 return 'Hide/Show pagination';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
486 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
487 formatRefresh: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
488 return 'Refresh';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
489 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
490 formatToggle: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
491 return 'Toggle';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
492 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
493 formatColumns: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
494 return 'Columns';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
495 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
496 formatAllRows: function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
497 return 'All';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
498 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
499 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
500
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
501 $.extend(BootstrapTable.DEFAULTS, BootstrapTable.LOCALES['en-US']);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
502
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
503 BootstrapTable.COLUMN_DEFAULTS = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
504 radio: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
505 checkbox: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
506 checkboxEnabled: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
507 field: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
508 title: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
509 titleTooltip: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
510 'class': undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
511 align: undefined, // left, right, center
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
512 halign: undefined, // left, right, center
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
513 falign: undefined, // left, right, center
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
514 valign: undefined, // top, middle, bottom
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
515 width: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
516 sortable: false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
517 order: 'asc', // asc, desc
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
518 visible: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
519 switchable: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
520 clickToSelect: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
521 formatter: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
522 footerFormatter: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
523 events: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
524 sorter: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
525 sortName: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
526 cellStyle: undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
527 searchable: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
528 searchFormatter: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
529 cardVisible: true,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
530 escape : false
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
531 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
532
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
533 BootstrapTable.EVENTS = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
534 'all.bs.table': 'onAll',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
535 'click-cell.bs.table': 'onClickCell',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
536 'dbl-click-cell.bs.table': 'onDblClickCell',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
537 'click-row.bs.table': 'onClickRow',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
538 'dbl-click-row.bs.table': 'onDblClickRow',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
539 'sort.bs.table': 'onSort',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
540 'check.bs.table': 'onCheck',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
541 'uncheck.bs.table': 'onUncheck',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
542 'check-all.bs.table': 'onCheckAll',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
543 'uncheck-all.bs.table': 'onUncheckAll',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
544 'check-some.bs.table': 'onCheckSome',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
545 'uncheck-some.bs.table': 'onUncheckSome',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
546 'load-success.bs.table': 'onLoadSuccess',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
547 'load-error.bs.table': 'onLoadError',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
548 'column-switch.bs.table': 'onColumnSwitch',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
549 'page-change.bs.table': 'onPageChange',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
550 'search.bs.table': 'onSearch',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
551 'toggle.bs.table': 'onToggle',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
552 'pre-body.bs.table': 'onPreBody',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
553 'post-body.bs.table': 'onPostBody',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
554 'post-header.bs.table': 'onPostHeader',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
555 'expand-row.bs.table': 'onExpandRow',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
556 'collapse-row.bs.table': 'onCollapseRow',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
557 'refresh-options.bs.table': 'onRefreshOptions',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
558 'reset-view.bs.table': 'onResetView',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
559 'refresh.bs.table': 'onRefresh'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
560 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
561
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
562 BootstrapTable.prototype.init = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
563 this.initLocale();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
564 this.initContainer();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
565 this.initTable();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
566 this.initHeader();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
567 this.initData();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
568 this.initHiddenRows();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
569 this.initFooter();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
570 this.initToolbar();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
571 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
572 this.initBody();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
573 this.initSearchText();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
574 this.initServer();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
575 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
576
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
577 BootstrapTable.prototype.initLocale = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
578 if (this.options.locale) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
579 var parts = this.options.locale.split(/-|_/);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
580 parts[0].toLowerCase();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
581 if (parts[1]) parts[1].toUpperCase();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
582 if ($.fn.bootstrapTable.locales[this.options.locale]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
583 // locale as requested
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
584 $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
585 } else if ($.fn.bootstrapTable.locales[parts.join('-')]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
586 // locale with sep set to - (in case original was specified with _)
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
587 $.extend(this.options, $.fn.bootstrapTable.locales[parts.join('-')]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
588 } else if ($.fn.bootstrapTable.locales[parts[0]]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
589 // short locale language code (i.e. 'en')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
590 $.extend(this.options, $.fn.bootstrapTable.locales[parts[0]]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
591 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
592 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
593 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
594
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
595 BootstrapTable.prototype.initContainer = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
596 this.$container = $([
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
597 '<div class="bootstrap-table">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
598 '<div class="fixed-table-toolbar"></div>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
599 this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
600 '<div class="fixed-table-pagination" style="clear: both;"></div>' :
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
601 '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
602 '<div class="fixed-table-container">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
603 '<div class="fixed-table-header"><table></table></div>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
604 '<div class="fixed-table-body">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
605 '<div class="fixed-table-loading">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
606 this.options.formatLoadingMessage(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
607 '</div>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
608 '</div>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
609 '<div class="fixed-table-footer"><table><tr></tr></table></div>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
610 this.options.paginationVAlign === 'bottom' || this.options.paginationVAlign === 'both' ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
611 '<div class="fixed-table-pagination"></div>' :
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
612 '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
613 '</div>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
614 '</div>'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
615 ].join(''));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
616
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
617 this.$container.insertAfter(this.$el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
618 this.$tableContainer = this.$container.find('.fixed-table-container');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
619 this.$tableHeader = this.$container.find('.fixed-table-header');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
620 this.$tableBody = this.$container.find('.fixed-table-body');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
621 this.$tableLoading = this.$container.find('.fixed-table-loading');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
622 this.$tableFooter = this.$container.find('.fixed-table-footer');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
623 this.$toolbar = this.$container.find('.fixed-table-toolbar');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
624 this.$pagination = this.$container.find('.fixed-table-pagination');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
625
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
626 this.$tableBody.append(this.$el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
627 this.$container.after('<div class="clearfix"></div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
628
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
629 this.$el.addClass(this.options.classes);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
630 if (this.options.striped) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
631 this.$el.addClass('table-striped');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
632 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
633 if ($.inArray('table-no-bordered', this.options.classes.split(' ')) !== -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
634 this.$tableContainer.addClass('table-no-bordered');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
635 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
636 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
637
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
638 BootstrapTable.prototype.initTable = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
639 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
640 columns = [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
641 data = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
642
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
643 this.$header = this.$el.find('>thead');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
644 if (!this.$header.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
645 this.$header = $('<thead></thead>').appendTo(this.$el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
646 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
647 this.$header.find('tr').each(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
648 var column = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
649
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
650 $(this).find('th').each(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
651 // Fix #2014 - getFieldIndex and elsewhere assume this is string, causes issues if not
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
652 if (typeof $(this).data('field') !== 'undefined') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
653 $(this).data('field', $(this).data('field') + '');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
654 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
655 column.push($.extend({}, {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
656 title: $(this).html(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
657 'class': $(this).attr('class'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
658 titleTooltip: $(this).attr('title'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
659 rowspan: $(this).attr('rowspan') ? +$(this).attr('rowspan') : undefined,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
660 colspan: $(this).attr('colspan') ? +$(this).attr('colspan') : undefined
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
661 }, $(this).data()));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
662 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
663 columns.push(column);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
664 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
665 if (!$.isArray(this.options.columns[0])) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
666 this.options.columns = [this.options.columns];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
667 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
668 this.options.columns = $.extend(true, [], columns, this.options.columns);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
669 this.columns = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
670
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
671 setFieldIndex(this.options.columns);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
672 $.each(this.options.columns, function (i, columns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
673 $.each(columns, function (j, column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
674 column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, column);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
675
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
676 if (typeof column.fieldIndex !== 'undefined') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
677 that.columns[column.fieldIndex] = column;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
678 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
679
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
680 that.options.columns[i][j] = column;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
681 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
682 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
683
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
684 // if options.data is setting, do not process tbody data
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
685 if (this.options.data.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
686 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
687 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
688
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
689 var m = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
690 this.$el.find('>tbody>tr').each(function (y) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
691 var row = {};
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
692
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
693 // save tr's id, class and data-* attributes
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
694 row._id = $(this).attr('id');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
695 row._class = $(this).attr('class');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
696 row._data = getRealDataAttr($(this).data());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
697
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
698 $(this).find('>td').each(function (x) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
699 var $this = $(this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
700 cspan = +$this.attr('colspan') || 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
701 rspan = +$this.attr('rowspan') || 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
702 tx, ty;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
703
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
704 for (; m[y] && m[y][x]; x++); //skip already occupied cells in current row
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
705
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
706 for (tx = x; tx < x + cspan; tx++) { //mark matrix elements occupied by current cell with true
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
707 for (ty = y; ty < y + rspan; ty++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
708 if (!m[ty]) { //fill missing rows
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
709 m[ty] = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
710 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
711 m[ty][tx] = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
712 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
713 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
714
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
715 var field = that.columns[x].field;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
716
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
717 row[field] = $(this).html();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
718 // save td's id, class and data-* attributes
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
719 row['_' + field + '_id'] = $(this).attr('id');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
720 row['_' + field + '_class'] = $(this).attr('class');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
721 row['_' + field + '_rowspan'] = $(this).attr('rowspan');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
722 row['_' + field + '_colspan'] = $(this).attr('colspan');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
723 row['_' + field + '_title'] = $(this).attr('title');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
724 row['_' + field + '_data'] = getRealDataAttr($(this).data());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
725 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
726 data.push(row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
727 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
728 this.options.data = data;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
729 if (data.length) this.fromHtml = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
730 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
731
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
732 BootstrapTable.prototype.initHeader = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
733 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
734 visibleColumns = {},
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
735 html = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
736
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
737 this.header = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
738 fields: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
739 styles: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
740 classes: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
741 formatters: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
742 events: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
743 sorters: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
744 sortNames: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
745 cellStyles: [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
746 searchables: []
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
747 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
748
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
749 $.each(this.options.columns, function (i, columns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
750 html.push('<tr>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
751
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
752 if (i === 0 && !that.options.cardView && that.options.detailView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
753 html.push(sprintf('<th class="detail" rowspan="%s"><div class="fht-cell"></div></th>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
754 that.options.columns.length));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
755 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
756
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
757 $.each(columns, function (j, column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
758 var text = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
759 halign = '', // header align style
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
760 align = '', // body align style
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
761 style = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
762 class_ = sprintf(' class="%s"', column['class']),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
763 order = that.options.sortOrder || column.order,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
764 unitWidth = 'px',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
765 width = column.width;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
766
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
767 if (column.width !== undefined && (!that.options.cardView)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
768 if (typeof column.width === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
769 if (column.width.indexOf('%') !== -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
770 unitWidth = '%';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
771 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
772 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
773 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
774 if (column.width && typeof column.width === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
775 width = column.width.replace('%', '').replace('px', '');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
776 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
777
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
778 halign = sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
779 align = sprintf('text-align: %s; ', column.align);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
780 style = sprintf('vertical-align: %s; ', column.valign);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
781 style += sprintf('width: %s; ', (column.checkbox || column.radio) && !width ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
782 '36px' : (width ? width + unitWidth : undefined));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
783
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
784 if (typeof column.fieldIndex !== 'undefined') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
785 that.header.fields[column.fieldIndex] = column.field;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
786 that.header.styles[column.fieldIndex] = align + style;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
787 that.header.classes[column.fieldIndex] = class_;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
788 that.header.formatters[column.fieldIndex] = column.formatter;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
789 that.header.events[column.fieldIndex] = column.events;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
790 that.header.sorters[column.fieldIndex] = column.sorter;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
791 that.header.sortNames[column.fieldIndex] = column.sortName;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
792 that.header.cellStyles[column.fieldIndex] = column.cellStyle;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
793 that.header.searchables[column.fieldIndex] = column.searchable;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
794
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
795 if (!column.visible) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
796 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
797 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
798
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
799 if (that.options.cardView && (!column.cardVisible)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
800 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
801 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
802
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
803 visibleColumns[column.field] = column;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
804 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
805
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
806 html.push('<th' + sprintf(' title="%s"', column.titleTooltip),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
807 column.checkbox || column.radio ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
808 sprintf(' class="bs-checkbox %s"', column['class'] || '') :
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
809 class_,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
810 sprintf(' style="%s"', halign + style),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
811 sprintf(' rowspan="%s"', column.rowspan),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
812 sprintf(' colspan="%s"', column.colspan),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
813 sprintf(' data-field="%s"', column.field),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
814 '>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
815
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
816 html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
817 'sortable both' : ''));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
818
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
819 text = that.options.escape ? escapeHTML(column.title) : column.title;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
820
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
821 if (column.checkbox) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
822 if (!that.options.singleSelect && that.options.checkboxHeader) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
823 text = '<input name="btSelectAll" type="checkbox" />';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
824 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
825 that.header.stateField = column.field;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
826 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
827 if (column.radio) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
828 text = '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
829 that.header.stateField = column.field;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
830 that.options.singleSelect = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
831 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
832
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
833 html.push(text);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
834 html.push('</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
835 html.push('<div class="fht-cell"></div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
836 html.push('</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
837 html.push('</th>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
838 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
839 html.push('</tr>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
840 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
841
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
842 this.$header.html(html.join(''));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
843 this.$header.find('th[data-field]').each(function (i) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
844 $(this).data(visibleColumns[$(this).data('field')]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
845 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
846 this.$container.off('click', '.th-inner').on('click', '.th-inner', function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
847 var target = $(this);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
848
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
849 if (that.options.detailView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
850 if (target.closest('.bootstrap-table')[0] !== that.$container[0])
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
851 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
852 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
853
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
854 if (that.options.sortable && target.parent().data().sortable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
855 that.onSort(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
856 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
857 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
858
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
859 this.$header.children().children().off('keypress').on('keypress', function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
860 if (that.options.sortable && $(this).data().sortable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
861 var code = event.keyCode || event.which;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
862 if (code == 13) { //Enter keycode
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
863 that.onSort(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
864 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
865 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
866 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
867
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
868 $(window).off('resize.bootstrap-table');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
869 if (!this.options.showHeader || this.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
870 this.$header.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
871 this.$tableHeader.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
872 this.$tableLoading.css('top', 0);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
873 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
874 this.$header.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
875 this.$tableHeader.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
876 this.$tableLoading.css('top', this.$header.outerHeight() + 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
877 // Assign the correct sortable arrow
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
878 this.getCaret();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
879 $(window).on('resize.bootstrap-table', $.proxy(this.resetWidth, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
880 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
881
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
882 this.$selectAll = this.$header.find('[name="btSelectAll"]');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
883 this.$selectAll.off('click').on('click', function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
884 var checked = $(this).prop('checked');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
885 that[checked ? 'checkAll' : 'uncheckAll']();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
886 that.updateSelected();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
887 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
888 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
889
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
890 BootstrapTable.prototype.initFooter = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
891 if (!this.options.showFooter || this.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
892 this.$tableFooter.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
893 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
894 this.$tableFooter.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
895 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
896 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
897
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
898 /**
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
899 * @param data
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
900 * @param type: append / prepend
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
901 */
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
902 BootstrapTable.prototype.initData = function (data, type) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
903 if (type === 'append') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
904 this.data = this.data.concat(data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
905 } else if (type === 'prepend') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
906 this.data = [].concat(data).concat(this.data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
907 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
908 this.data = data || this.options.data;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
909 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
910
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
911 // Fix #839 Records deleted when adding new row on filtered table
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
912 if (type === 'append') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
913 this.options.data = this.options.data.concat(data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
914 } else if (type === 'prepend') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
915 this.options.data = [].concat(data).concat(this.options.data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
916 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
917 this.options.data = this.data;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
918 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
919
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
920 if (this.options.sidePagination === 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
921 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
922 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
923 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
924 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
925
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
926 BootstrapTable.prototype.initSort = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
927 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
928 name = this.options.sortName,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
929 order = this.options.sortOrder === 'desc' ? -1 : 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
930 index = $.inArray(this.options.sortName, this.header.fields),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
931 timeoutId = 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
932
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
933 if (this.options.customSort !== $.noop) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
934 this.options.customSort.apply(this, [this.options.sortName, this.options.sortOrder]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
935 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
936 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
937
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
938 if (index !== -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
939 if (this.options.sortStable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
940 $.each(this.data, function (i, row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
941 if (!row.hasOwnProperty('_position')) row._position = i;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
942 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
943 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
944
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
945 this.data.sort(function (a, b) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
946 if (that.header.sortNames[index]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
947 name = that.header.sortNames[index];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
948 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
949 var aa = getItemField(a, name, that.options.escape),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
950 bb = getItemField(b, name, that.options.escape),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
951 value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
952
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
953 if (value !== undefined) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
954 return order * value;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
955 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
956
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
957 // Fix #161: undefined or null string sort bug.
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
958 if (aa === undefined || aa === null) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
959 aa = '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
960 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
961 if (bb === undefined || bb === null) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
962 bb = '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
963 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
964
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
965 if (that.options.sortStable && aa === bb) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
966 aa = a._position;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
967 bb = b._position;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
968 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
969
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
970 // IF both values are numeric, do a numeric comparison
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
971 if ($.isNumeric(aa) && $.isNumeric(bb)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
972 // Convert numerical values form string to float.
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
973 aa = parseFloat(aa);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
974 bb = parseFloat(bb);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
975 if (aa < bb) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
976 return order * -1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
977 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
978 return order;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
979 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
980
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
981 if (aa === bb) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
982 return 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
983 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
984
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
985 // If value is not a string, convert to string
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
986 if (typeof aa !== 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
987 aa = aa.toString();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
988 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
989
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
990 if (aa.localeCompare(bb) === -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
991 return order * -1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
992 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
993
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
994 return order;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
995 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
996
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
997 if (this.options.sortClass !== undefined) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
998 clearTimeout(timeoutId);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
999 timeoutId = setTimeout(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1000 that.$el.removeClass(that.options.sortClass);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1001 var index = that.$header.find(sprintf('[data-field="%s"]',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1002 that.options.sortName).index() + 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1003 that.$el.find(sprintf('tr td:nth-child(%s)', index))
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1004 .addClass(that.options.sortClass);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1005 }, 250);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1006 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1007 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1008 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1009
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1010 BootstrapTable.prototype.onSort = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1011 var $this = event.type === "keypress" ? $(event.currentTarget) : $(event.currentTarget).parent(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1012 $this_ = this.$header.find('th').eq($this.index());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1013
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1014 this.$header.add(this.$header_).find('span.order').remove();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1015
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1016 if (this.options.sortName === $this.data('field')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1017 this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1018 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1019 this.options.sortName = $this.data('field');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1020 this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1021 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1022 this.trigger('sort', this.options.sortName, this.options.sortOrder);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1023
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1024 $this.add($this_).data('order', this.options.sortOrder);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1025
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1026 // Assign the correct sortable arrow
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1027 this.getCaret();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1028
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1029 if (this.options.sidePagination === 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1030 this.initServer(this.options.silentSort);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1031 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1032 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1033
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1034 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1035 this.initBody();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1036 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1037
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1038 BootstrapTable.prototype.initToolbar = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1039 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1040 html = [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1041 timeoutId = 0,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1042 $keepOpen,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1043 $search,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1044 switchableCount = 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1045
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1046 if (this.$toolbar.find('.bs-bars').children().length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1047 $('body').append($(this.options.toolbar));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1048 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1049 this.$toolbar.html('');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1050
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1051 if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1052 $(sprintf('<div class="bs-bars pull-%s"></div>', this.options.toolbarAlign))
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1053 .appendTo(this.$toolbar)
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1054 .append($(this.options.toolbar));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1055 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1056
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1057 // showColumns, showToggle, showRefresh
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1058 html = [sprintf('<div class="columns columns-%s btn-group pull-%s">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1059 this.options.buttonsAlign, this.options.buttonsAlign)];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1060
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1061 if (typeof this.options.icons === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1062 this.options.icons = calculateObjectValue(null, this.options.icons);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1063 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1064
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1065 if (this.options.showPaginationSwitch) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1066 html.push(sprintf('<button class="btn' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1067 sprintf(' btn-%s', this.options.buttonsClass) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1068 sprintf(' btn-%s', this.options.iconSize) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1069 '" type="button" name="paginationSwitch" aria-label="pagination Switch" title="%s">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1070 this.options.formatPaginationSwitch()),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1071 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1072 '</button>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1073 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1074
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1075 if (this.options.showRefresh) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1076 html.push(sprintf('<button class="btn' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1077 sprintf(' btn-%s', this.options.buttonsClass) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1078 sprintf(' btn-%s', this.options.iconSize) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1079 '" type="button" name="refresh" aria-label="refresh" title="%s">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1080 this.options.formatRefresh()),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1081 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1082 '</button>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1083 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1084
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1085 if (this.options.showToggle) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1086 html.push(sprintf('<button class="btn' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1087 sprintf(' btn-%s', this.options.buttonsClass) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1088 sprintf(' btn-%s', this.options.iconSize) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1089 '" type="button" name="toggle" aria-label="toggle" title="%s">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1090 this.options.formatToggle()),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1091 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1092 '</button>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1093 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1094
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1095 if (this.options.showColumns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1096 html.push(sprintf('<div class="keep-open btn-group" title="%s">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1097 this.options.formatColumns()),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1098 '<button type="button" aria-label="columns" class="btn' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1099 sprintf(' btn-%s', this.options.buttonsClass) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1100 sprintf(' btn-%s', this.options.iconSize) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1101 ' dropdown-toggle" data-toggle="dropdown">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1102 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1103 ' <span class="caret"></span>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1104 '</button>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1105 '<ul class="dropdown-menu" role="menu">');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1106
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1107 $.each(this.columns, function (i, column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1108 if (column.radio || column.checkbox) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1109 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1110 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1111
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1112 if (that.options.cardView && !column.cardVisible) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1113 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1114 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1115
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1116 var checked = column.visible ? ' checked="checked"' : '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1117
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1118 if (column.switchable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1119 html.push(sprintf('<li role="menuitem">' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1120 '<label><input type="checkbox" data-field="%s" value="%s"%s> %s</label>' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1121 '</li>', column.field, i, checked, column.title));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1122 switchableCount++;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1123 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1124 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1125 html.push('</ul>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1126 '</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1127 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1128
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1129 html.push('</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1130
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1131 // Fix #188: this.showToolbar is for extensions
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1132 if (this.showToolbar || html.length > 2) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1133 this.$toolbar.append(html.join(''));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1134 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1135
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1136 if (this.options.showPaginationSwitch) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1137 this.$toolbar.find('button[name="paginationSwitch"]')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1138 .off('click').on('click', $.proxy(this.togglePagination, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1139 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1140
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1141 if (this.options.showRefresh) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1142 this.$toolbar.find('button[name="refresh"]')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1143 .off('click').on('click', $.proxy(this.refresh, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1144 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1145
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1146 if (this.options.showToggle) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1147 this.$toolbar.find('button[name="toggle"]')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1148 .off('click').on('click', function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1149 that.toggleView();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1150 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1151 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1152
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1153 if (this.options.showColumns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1154 $keepOpen = this.$toolbar.find('.keep-open');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1155
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1156 if (switchableCount <= this.options.minimumCountColumns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1157 $keepOpen.find('input').prop('disabled', true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1158 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1159
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1160 $keepOpen.find('li').off('click').on('click', function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1161 event.stopImmediatePropagation();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1162 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1163 $keepOpen.find('input').off('click').on('click', function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1164 var $this = $(this);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1165
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1166 that.toggleColumn($(this).val(), $this.prop('checked'), false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1167 that.trigger('column-switch', $(this).data('field'), $this.prop('checked'));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1168 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1169 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1170
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1171 if (this.options.search) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1172 html = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1173 html.push(
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1174 '<div class="pull-' + this.options.searchAlign + ' search">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1175 sprintf('<input class="form-control' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1176 sprintf(' input-%s', this.options.iconSize) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1177 '" type="text" placeholder="%s">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1178 this.options.formatSearch()),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1179 '</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1180
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1181 this.$toolbar.append(html.join(''));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1182 $search = this.$toolbar.find('.search input');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1183 $search.off('keyup drop blur').on('keyup drop blur', function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1184 if (that.options.searchOnEnterKey && event.keyCode !== 13) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1185 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1186 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1187
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1188 if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1189 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1190 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1191
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1192 clearTimeout(timeoutId); // doesn't matter if it's 0
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1193 timeoutId = setTimeout(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1194 that.onSearch(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1195 }, that.options.searchTimeOut);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1196 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1197
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1198 if (isIEBrowser()) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1199 $search.off('mouseup').on('mouseup', function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1200 clearTimeout(timeoutId); // doesn't matter if it's 0
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1201 timeoutId = setTimeout(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1202 that.onSearch(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1203 }, that.options.searchTimeOut);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1204 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1205 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1206 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1207 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1208
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1209 BootstrapTable.prototype.onSearch = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1210 var text = $.trim($(event.currentTarget).val());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1211
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1212 // trim search input
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1213 if (this.options.trimOnSearch && $(event.currentTarget).val() !== text) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1214 $(event.currentTarget).val(text);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1215 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1216
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1217 if (text === this.searchText) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1218 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1219 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1220 this.searchText = text;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1221 this.options.searchText = text;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1222
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1223 this.options.pageNumber = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1224 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1225 this.updatePagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1226 this.trigger('search', text);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1227 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1228
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1229 BootstrapTable.prototype.initSearch = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1230 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1231
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1232 if (this.options.sidePagination !== 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1233 if (this.options.customSearch !== $.noop) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1234 this.options.customSearch.apply(this, [this.searchText]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1235 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1236 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1237
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1238 var s = this.searchText && (this.options.escape ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1239 escapeHTML(this.searchText) : this.searchText).toLowerCase();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1240 var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1241
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1242 // Check filter
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1243 this.data = f ? $.grep(this.options.data, function (item, i) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1244 for (var key in f) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1245 if ($.isArray(f[key]) && $.inArray(item[key], f[key]) === -1 ||
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1246 !$.isArray(f[key]) && item[key] !== f[key]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1247 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1248 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1249 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1250 return true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1251 }) : this.options.data;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1252
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1253 this.data = s ? $.grep(this.data, function (item, i) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1254 for (var j = 0; j < that.header.fields.length; j++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1255
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1256 if (!that.header.searchables[j]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1257 continue;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1258 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1259
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1260 var key = $.isNumeric(that.header.fields[j]) ? parseInt(that.header.fields[j], 10) : that.header.fields[j];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1261 var column = that.columns[getFieldIndex(that.columns, key)];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1262 var value;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1263
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1264 if (typeof key === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1265 value = item;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1266 var props = key.split('.');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1267 for (var prop_index = 0; prop_index < props.length; prop_index++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1268 value = value[props[prop_index]];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1269 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1270
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1271 // Fix #142: respect searchForamtter boolean
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1272 if (column && column.searchFormatter) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1273 value = calculateObjectValue(column,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1274 that.header.formatters[j], [value, item, i], value);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1275 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1276 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1277 value = item[key];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1278 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1279
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1280 if (typeof value === 'string' || typeof value === 'number') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1281 if (that.options.strictSearch) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1282 if ((value + '').toLowerCase() === s) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1283 return true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1284 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1285 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1286 if ((value + '').toLowerCase().indexOf(s) !== -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1287 return true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1288 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1289 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1290 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1291 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1292 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1293 }) : this.data;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1294 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1295 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1296
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1297 BootstrapTable.prototype.initPagination = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1298 if (!this.options.pagination) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1299 this.$pagination.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1300 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1301 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1302 this.$pagination.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1303 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1304
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1305 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1306 html = [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1307 $allSelected = false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1308 i, from, to,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1309 $pageList,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1310 $first, $pre,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1311 $next, $last,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1312 $number,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1313 data = this.getData(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1314 pageList = this.options.pageList;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1315
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1316 if (this.options.sidePagination !== 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1317 this.options.totalRows = data.length;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1318 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1319
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1320 this.totalPages = 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1321 if (this.options.totalRows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1322 if (this.options.pageSize === this.options.formatAllRows()) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1323 this.options.pageSize = this.options.totalRows;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1324 $allSelected = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1325 } else if (this.options.pageSize === this.options.totalRows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1326 // Fix #667 Table with pagination,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1327 // multiple pages and a search that matches to one page throws exception
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1328 var pageLst = typeof this.options.pageList === 'string' ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1329 this.options.pageList.replace('[', '').replace(']', '')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1330 .replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1331 if ($.inArray(this.options.formatAllRows().toLowerCase(), pageLst) > -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1332 $allSelected = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1333 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1334 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1335
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1336 this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1337
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1338 this.options.totalPages = this.totalPages;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1339 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1340 if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1341 this.options.pageNumber = this.totalPages;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1342 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1343
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1344 this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1345 this.pageTo = this.options.pageNumber * this.options.pageSize;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1346 if (this.pageTo > this.options.totalRows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1347 this.pageTo = this.options.totalRows;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1348 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1349
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1350 html.push(
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1351 '<div class="pull-' + this.options.paginationDetailHAlign + ' pagination-detail">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1352 '<span class="pagination-info">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1353 this.options.onlyInfoPagination ? this.options.formatDetailPagination(this.options.totalRows) :
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1354 this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1355 '</span>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1356
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1357 if (!this.options.onlyInfoPagination) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1358 html.push('<span class="page-list">');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1359
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1360 var pageNumber = [
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1361 sprintf('<span class="btn-group %s">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1362 this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1363 'dropdown' : 'dropup'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1364 '<button type="button" class="btn' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1365 sprintf(' btn-%s', this.options.buttonsClass) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1366 sprintf(' btn-%s', this.options.iconSize) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1367 ' dropdown-toggle" data-toggle="dropdown">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1368 '<span class="page-size">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1369 $allSelected ? this.options.formatAllRows() : this.options.pageSize,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1370 '</span>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1371 ' <span class="caret"></span>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1372 '</button>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1373 '<ul class="dropdown-menu" role="menu">'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1374 ];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1375
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1376 if (typeof this.options.pageList === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1377 var list = this.options.pageList.replace('[', '').replace(']', '')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1378 .replace(/ /g, '').split(',');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1379
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1380 pageList = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1381 $.each(list, function (i, value) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1382 pageList.push(value.toUpperCase() === that.options.formatAllRows().toUpperCase() ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1383 that.options.formatAllRows() : +value);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1384 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1385 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1386
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1387 $.each(pageList, function (i, page) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1388 if (!that.options.smartDisplay || i === 0 || pageList[i - 1] < that.options.totalRows) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1389 var active;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1390 if ($allSelected) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1391 active = page === that.options.formatAllRows() ? ' class="active"' : '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1392 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1393 active = page === that.options.pageSize ? ' class="active"' : '';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1394 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1395 pageNumber.push(sprintf('<li role="menuitem"%s><a href="#">%s</a></li>', active, page));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1396 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1397 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1398 pageNumber.push('</ul></span>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1399
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1400 html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1401 html.push('</span>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1402
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1403 html.push('</div>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1404 '<div class="pull-' + this.options.paginationHAlign + ' pagination">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1405 '<ul class="pagination' + sprintf(' pagination-%s', this.options.iconSize) + '">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1406 '<li class="page-pre"><a href="#">' + this.options.paginationPreText + '</a></li>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1407
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1408 if (this.totalPages < 5) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1409 from = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1410 to = this.totalPages;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1411 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1412 from = this.options.pageNumber - 2;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1413 to = from + 4;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1414 if (from < 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1415 from = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1416 to = 5;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1417 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1418 if (to > this.totalPages) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1419 to = this.totalPages;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1420 from = to - 4;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1421 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1422 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1423
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1424 if (this.totalPages >= 6) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1425 if (this.options.pageNumber >= 3) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1426 html.push('<li class="page-first' + (1 === this.options.pageNumber ? ' active' : '') + '">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1427 '<a href="#">', 1, '</a>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1428 '</li>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1429
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1430 from++;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1431 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1432
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1433 if (this.options.pageNumber >= 4) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1434 if (this.options.pageNumber == 4 || this.totalPages == 6 || this.totalPages == 7) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1435 from--;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1436 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1437 html.push('<li class="page-first-separator disabled">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1438 '<a href="#">...</a>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1439 '</li>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1440 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1441
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1442 to--;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1443 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1444 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1445
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1446 if (this.totalPages >= 7) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1447 if (this.options.pageNumber >= (this.totalPages - 2)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1448 from--;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1449 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1450 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1451
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1452 if (this.totalPages == 6) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1453 if (this.options.pageNumber >= (this.totalPages - 2)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1454 to++;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1455 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1456 } else if (this.totalPages >= 7) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1457 if (this.totalPages == 7 || this.options.pageNumber >= (this.totalPages - 3)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1458 to++;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1459 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1460 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1461
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1462 for (i = from; i <= to; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1463 html.push('<li class="page-number' + (i === this.options.pageNumber ? ' active' : '') + '">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1464 '<a href="#">', i, '</a>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1465 '</li>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1466 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1467
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1468 if (this.totalPages >= 8) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1469 if (this.options.pageNumber <= (this.totalPages - 4)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1470 html.push('<li class="page-last-separator disabled">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1471 '<a href="#">...</a>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1472 '</li>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1473 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1474 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1475
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1476 if (this.totalPages >= 6) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1477 if (this.options.pageNumber <= (this.totalPages - 3)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1478 html.push('<li class="page-last' + (this.totalPages === this.options.pageNumber ? ' active' : '') + '">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1479 '<a href="#">', this.totalPages, '</a>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1480 '</li>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1481 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1482 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1483
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1484 html.push(
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1485 '<li class="page-next"><a href="#">' + this.options.paginationNextText + '</a></li>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1486 '</ul>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1487 '</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1488 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1489 this.$pagination.html(html.join(''));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1490
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1491 if (!this.options.onlyInfoPagination) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1492 $pageList = this.$pagination.find('.page-list a');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1493 $first = this.$pagination.find('.page-first');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1494 $pre = this.$pagination.find('.page-pre');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1495 $next = this.$pagination.find('.page-next');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1496 $last = this.$pagination.find('.page-last');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1497 $number = this.$pagination.find('.page-number');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1498
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1499 if (this.options.smartDisplay) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1500 if (this.totalPages <= 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1501 this.$pagination.find('div.pagination').hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1502 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1503 if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1504 this.$pagination.find('span.page-list').hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1505 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1506
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1507 // when data is empty, hide the pagination
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1508 this.$pagination[this.getData().length ? 'show' : 'hide']();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1509 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1510
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1511 if (!this.options.paginationLoop) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1512 if (this.options.pageNumber === 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1513 $pre.addClass('disabled');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1514 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1515 if (this.options.pageNumber === this.totalPages) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1516 $next.addClass('disabled');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1517 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1518 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1519
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1520 if ($allSelected) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1521 this.options.pageSize = this.options.formatAllRows();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1522 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1523 $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1524 $first.off('click').on('click', $.proxy(this.onPageFirst, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1525 $pre.off('click').on('click', $.proxy(this.onPagePre, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1526 $next.off('click').on('click', $.proxy(this.onPageNext, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1527 $last.off('click').on('click', $.proxy(this.onPageLast, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1528 $number.off('click').on('click', $.proxy(this.onPageNumber, this));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1529 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1530 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1531
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1532 BootstrapTable.prototype.updatePagination = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1533 // Fix #171: IE disabled button can be clicked bug.
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1534 if (event && $(event.currentTarget).hasClass('disabled')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1535 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1536 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1537
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1538 if (!this.options.maintainSelected) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1539 this.resetRows();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1540 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1541
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1542 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1543 if (this.options.sidePagination === 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1544 this.initServer();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1545 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1546 this.initBody();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1547 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1548
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1549 this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1550 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1551
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1552 BootstrapTable.prototype.onPageListChange = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1553 var $this = $(event.currentTarget);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1554
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1555 $this.parent().addClass('active').siblings().removeClass('active');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1556 this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1557 this.options.formatAllRows() : +$this.text();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1558 this.$toolbar.find('.page-size').text(this.options.pageSize);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1559
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1560 this.updatePagination(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1561 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1562 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1563
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1564 BootstrapTable.prototype.onPageFirst = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1565 this.options.pageNumber = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1566 this.updatePagination(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1567 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1568 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1569
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1570 BootstrapTable.prototype.onPagePre = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1571 if ((this.options.pageNumber - 1) === 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1572 this.options.pageNumber = this.options.totalPages;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1573 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1574 this.options.pageNumber--;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1575 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1576 this.updatePagination(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1577 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1578 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1579
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1580 BootstrapTable.prototype.onPageNext = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1581 if ((this.options.pageNumber + 1) > this.options.totalPages) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1582 this.options.pageNumber = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1583 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1584 this.options.pageNumber++;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1585 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1586 this.updatePagination(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1587 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1588 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1589
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1590 BootstrapTable.prototype.onPageLast = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1591 this.options.pageNumber = this.totalPages;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1592 this.updatePagination(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1593 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1594 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1595
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1596 BootstrapTable.prototype.onPageNumber = function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1597 if (this.options.pageNumber === +$(event.currentTarget).text()) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1598 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1599 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1600 this.options.pageNumber = +$(event.currentTarget).text();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1601 this.updatePagination(event);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1602 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1603 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1604
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1605 BootstrapTable.prototype.initRow = function(item, i, data, parentDom) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1606 var that=this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1607 key,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1608 html = [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1609 style = {},
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1610 csses = [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1611 data_ = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1612 attributes = {},
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1613 htmlAttributes = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1614
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1615 if ($.inArray(item, this.hiddenRows) > -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1616 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1617 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1618
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1619 style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1620
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1621 if (style && style.css) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1622 for (key in style.css) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1623 csses.push(key + ': ' + style.css[key]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1624 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1625 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1626
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1627 attributes = calculateObjectValue(this.options,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1628 this.options.rowAttributes, [item, i], attributes);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1629
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1630 if (attributes) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1631 for (key in attributes) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1632 htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1633 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1634 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1635
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1636 if (item._data && !$.isEmptyObject(item._data)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1637 $.each(item._data, function(k, v) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1638 // ignore data-index
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1639 if (k === 'index') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1640 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1641 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1642 data_ += sprintf(' data-%s="%s"', k, v);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1643 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1644 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1645
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1646 html.push('<tr',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1647 sprintf(' %s', htmlAttributes.join(' ')),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1648 sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1649 sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1650 sprintf(' data-index="%s"', i),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1651 sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1652 sprintf('%s', data_),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1653 '>'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1654 );
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1655
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1656 if (this.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1657 html.push(sprintf('<td colspan="%s"><div class="card-views">', this.header.fields.length));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1658 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1659
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1660 if (!this.options.cardView && this.options.detailView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1661 html.push('<td>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1662 '<a class="detail-icon" href="#">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1663 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1664 '</a>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1665 '</td>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1666 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1667
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1668 $.each(this.header.fields, function(j, field) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1669 var text = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1670 value_ = getItemField(item, field, that.options.escape),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1671 value = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1672 type = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1673 cellStyle = {},
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1674 id_ = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1675 class_ = that.header.classes[j],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1676 data_ = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1677 rowspan_ = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1678 colspan_ = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1679 title_ = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1680 column = that.columns[j];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1681
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1682 if (that.fromHtml && typeof value_ === 'undefined') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1683 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1684 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1685
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1686 if (!column.visible) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1687 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1688 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1689
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1690 if (that.options.cardView && (!column.cardVisible)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1691 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1692 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1693
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1694 if (column.escape) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1695 value_ = escapeHTML(value_);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1696 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1697
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1698 style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1699
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1700 // handle td's id and class
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1701 if (item['_' + field + '_id']) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1702 id_ = sprintf(' id="%s"', item['_' + field + '_id']);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1703 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1704 if (item['_' + field + '_class']) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1705 class_ = sprintf(' class="%s"', item['_' + field + '_class']);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1706 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1707 if (item['_' + field + '_rowspan']) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1708 rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1709 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1710 if (item['_' + field + '_colspan']) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1711 colspan_ = sprintf(' colspan="%s"', item['_' + field + '_colspan']);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1712 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1713 if (item['_' + field + '_title']) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1714 title_ = sprintf(' title="%s"', item['_' + field + '_title']);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1715 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1716 cellStyle = calculateObjectValue(that.header,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1717 that.header.cellStyles[j], [value_, item, i, field], cellStyle);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1718 if (cellStyle.classes) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1719 class_ = sprintf(' class="%s"', cellStyle.classes);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1720 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1721 if (cellStyle.css) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1722 var csses_ = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1723 for (var key in cellStyle.css) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1724 csses_.push(key + ': ' + cellStyle.css[key]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1725 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1726 style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1727 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1728
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1729 value = calculateObjectValue(column,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1730 that.header.formatters[j], [value_, item, i], value_);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1731
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1732 if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1733 $.each(item['_' + field + '_data'], function(k, v) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1734 // ignore data-index
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1735 if (k === 'index') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1736 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1737 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1738 data_ += sprintf(' data-%s="%s"', k, v);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1739 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1740 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1741
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1742 if (column.checkbox || column.radio) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1743 type = column.checkbox ? 'checkbox' : type;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1744 type = column.radio ? 'radio' : type;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1745
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1746 text = [sprintf(that.options.cardView ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1747 '<div class="card-view %s">' : '<td class="bs-checkbox %s">', column['class'] || ''),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1748 '<input' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1749 sprintf(' data-index="%s"', i) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1750 sprintf(' name="%s"', that.options.selectItemName) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1751 sprintf(' type="%s"', type) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1752 sprintf(' value="%s"', item[that.options.idField]) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1753 sprintf(' checked="%s"', value === true ||
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1754 (value_ || value && value.checked) ? 'checked' : undefined) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1755 sprintf(' disabled="%s"', !column.checkboxEnabled ||
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1756 (value && value.disabled) ? 'disabled' : undefined) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1757 ' />',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1758 that.header.formatters[j] && typeof value === 'string' ? value : '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1759 that.options.cardView ? '</div>' : '</td>'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1760 ].join('');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1761
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1762 item[that.header.stateField] = value === true || (value && value.checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1763 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1764 value = typeof value === 'undefined' || value === null ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1765 that.options.undefinedText : value;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1766
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1767 text = that.options.cardView ? ['<div class="card-view">',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1768 that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1769 getPropertyFromOther(that.columns, 'field', 'title', field)) : '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1770 sprintf('<span class="value">%s</span>', value),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1771 '</div>'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1772 ].join('') : [sprintf('<td%s %s %s %s %s %s %s>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1773 id_, class_, style, data_, rowspan_, colspan_, title_),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1774 value,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1775 '</td>'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1776 ].join('');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1777
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1778 // Hide empty data on Card view when smartDisplay is set to true.
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1779 if (that.options.cardView && that.options.smartDisplay && value === '') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1780 // Should set a placeholder for event binding correct fieldIndex
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1781 text = '<div class="card-view"></div>';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1782 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1783 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1784
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1785 html.push(text);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1786 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1787
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1788 if (this.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1789 html.push('</div></td>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1790 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1791 html.push('</tr>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1792
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1793 return html.join(' ');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1794 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1795
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1796 BootstrapTable.prototype.initBody = function (fixedScroll) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1797 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1798 html = [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1799 data = this.getData();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1800
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1801 this.trigger('pre-body', data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1802
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1803 this.$body = this.$el.find('>tbody');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1804 if (!this.$body.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1805 this.$body = $('<tbody></tbody>').appendTo(this.$el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1806 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1807
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1808 //Fix #389 Bootstrap-table-flatJSON is not working
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1809
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1810 if (!this.options.pagination || this.options.sidePagination === 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1811 this.pageFrom = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1812 this.pageTo = data.length;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1813 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1814
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1815 var trFragments = $(document.createDocumentFragment());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1816 var hasTr;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1817
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1818 for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1819 var item = data[i];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1820 var tr = this.initRow(item, i, data, trFragments);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1821 hasTr = hasTr || !!tr;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1822 if (tr&&tr!==true) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1823 trFragments.append(tr);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1824 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1825 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1826
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1827 // show no records
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1828 if (!hasTr) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1829 trFragments.append('<tr class="no-records-found">' +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1830 sprintf('<td colspan="%s">%s</td>',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1831 this.$header.find('th').length,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1832 this.options.formatNoMatches()) +
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1833 '</tr>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1834 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1835
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1836 this.$body.html(trFragments);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1837
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1838 if (!fixedScroll) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1839 this.scrollTo(0);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1840 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1841
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1842 // click to select by column
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1843 this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1844 var $td = $(this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1845 $tr = $td.parent(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1846 item = that.data[$tr.data('index')],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1847 index = $td[0].cellIndex,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1848 fields = that.getVisibleFields(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1849 field = fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1850 column = that.columns[getFieldIndex(that.columns, field)],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1851 value = getItemField(item, field, that.options.escape);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1852
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1853 if ($td.find('.detail-icon').length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1854 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1855 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1856
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1857 that.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1858 that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1859
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1860 // if click to select - then trigger the checkbox/radio click
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1861 if (e.type === 'click' && that.options.clickToSelect && column.clickToSelect) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1862 var $selectItem = $tr.find(sprintf('[name="%s"]', that.options.selectItemName));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1863 if ($selectItem.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1864 $selectItem[0].click(); // #144: .trigger('click') bug
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1865 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1866 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1867 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1868
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1869 this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1870 var $this = $(this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1871 $tr = $this.parent().parent(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1872 index = $tr.data('index'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1873 row = data[index]; // Fix #980 Detail view, when searching, returns wrong row
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1874
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1875 // remove and update
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1876 if ($tr.next().is('tr.detail-view')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1877 $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailOpen));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1878 that.trigger('collapse-row', index, row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1879 $tr.next().remove();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1880 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1881 $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailClose));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1882 $tr.after(sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.find('td').length));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1883 var $element = $tr.next().find('td');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1884 var content = calculateObjectValue(that.options, that.options.detailFormatter, [index, row, $element], '');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1885 if($element.length === 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1886 $element.append(content);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1887 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1888 that.trigger('expand-row', index, row, $element);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1889 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1890 that.resetView();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1891 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1892 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1893
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1894 this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1895 this.$selectItem.off('click').on('click', function (event) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1896 event.stopImmediatePropagation();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1897
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1898 var $this = $(this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1899 checked = $this.prop('checked'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1900 row = that.data[$this.data('index')];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1901
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1902 if (that.options.maintainSelected && $(this).is(':radio')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1903 $.each(that.options.data, function (i, row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1904 row[that.header.stateField] = false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1905 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1906 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1907
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1908 row[that.header.stateField] = checked;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1909
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1910 if (that.options.singleSelect) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1911 that.$selectItem.not(this).each(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1912 that.data[$(this).data('index')][that.header.stateField] = false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1913 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1914 that.$selectItem.filter(':checked').not(this).prop('checked', false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1915 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1916
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1917 that.updateSelected();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1918 that.trigger(checked ? 'check' : 'uncheck', row, $this);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1919 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1920
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1921 $.each(this.header.events, function (i, events) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1922 if (!events) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1923 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1924 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1925 // fix bug, if events is defined with namespace
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1926 if (typeof events === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1927 events = calculateObjectValue(null, events);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1928 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1929
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1930 var field = that.header.fields[i],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1931 fieldIndex = $.inArray(field, that.getVisibleFields());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1932
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1933 if (that.options.detailView && !that.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1934 fieldIndex += 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1935 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1936
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1937 for (var key in events) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1938 that.$body.find('>tr:not(.no-records-found)').each(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1939 var $tr = $(this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1940 $td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(fieldIndex),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1941 index = key.indexOf(' '),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1942 name = key.substring(0, index),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1943 el = key.substring(index + 1),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1944 func = events[key];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1945
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1946 $td.find(el).off(name).on(name, function (e) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1947 var index = $tr.data('index'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1948 row = that.data[index],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1949 value = row[field];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1950
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1951 func.apply(this, [e, value, row, index]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1952 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1953 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1954 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1955 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1956
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1957 this.updateSelected();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1958 this.resetView();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1959
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1960 this.trigger('post-body', data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1961 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1962
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1963 BootstrapTable.prototype.initServer = function (silent, query, url) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1964 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1965 data = {},
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1966 params = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1967 searchText: this.searchText,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1968 sortName: this.options.sortName,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1969 sortOrder: this.options.sortOrder
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1970 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1971 request;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1972
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1973 if (this.options.pagination) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1974 params.pageSize = this.options.pageSize === this.options.formatAllRows() ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1975 this.options.totalRows : this.options.pageSize;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1976 params.pageNumber = this.options.pageNumber;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1977 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1978
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1979 if (!(url || this.options.url) && !this.options.ajax) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1980 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1981 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1982
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1983 if (this.options.queryParamsType === 'limit') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1984 params = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1985 search: params.searchText,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1986 sort: params.sortName,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1987 order: params.sortOrder
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1988 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1989
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1990 if (this.options.pagination) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1991 params.offset = this.options.pageSize === this.options.formatAllRows() ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1992 0 : this.options.pageSize * (this.options.pageNumber - 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1993 params.limit = this.options.pageSize === this.options.formatAllRows() ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1994 this.options.totalRows : this.options.pageSize;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1995 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1996 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1997
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1998 if (!($.isEmptyObject(this.filterColumnsPartial))) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
1999 params.filter = JSON.stringify(this.filterColumnsPartial, null);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2000 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2001
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2002 data = calculateObjectValue(this.options, this.options.queryParams, [params], data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2003
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2004 $.extend(data, query || {});
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2005
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2006 // false to stop request
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2007 if (data === false) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2008 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2009 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2010
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2011 if (!silent) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2012 this.$tableLoading.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2013 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2014 request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2015 type: this.options.method,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2016 url: url || this.options.url,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2017 data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2018 JSON.stringify(data) : data,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2019 cache: this.options.cache,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2020 contentType: this.options.contentType,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2021 dataType: this.options.dataType,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2022 success: function (res) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2023 res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2024
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2025 that.load(res);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2026 that.trigger('load-success', res);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2027 if (!silent) that.$tableLoading.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2028 },
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2029 error: function (res) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2030 that.trigger('load-error', res.status, res);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2031 if (!silent) that.$tableLoading.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2032 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2033 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2034
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2035 if (this.options.ajax) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2036 calculateObjectValue(this, this.options.ajax, [request], null);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2037 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2038 if (this._xhr && this._xhr.readyState !== 4) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2039 this._xhr.abort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2040 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2041 this._xhr = $.ajax(request);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2042 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2043 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2044
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2045 BootstrapTable.prototype.initSearchText = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2046 if (this.options.search) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2047 if (this.options.searchText !== '') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2048 var $search = this.$toolbar.find('.search input');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2049 $search.val(this.options.searchText);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2050 this.onSearch({currentTarget: $search});
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2051 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2052 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2053 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2054
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2055 BootstrapTable.prototype.getCaret = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2056 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2057
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2058 $.each(this.$header.find('th'), function (i, th) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2059 $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === that.options.sortName ? that.options.sortOrder : 'both');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2060 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2061 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2062
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2063 BootstrapTable.prototype.updateSelected = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2064 var checkAll = this.$selectItem.filter(':enabled').length &&
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2065 this.$selectItem.filter(':enabled').length ===
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2066 this.$selectItem.filter(':enabled').filter(':checked').length;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2067
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2068 this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2069
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2070 this.$selectItem.each(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2071 $(this).closest('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2072 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2073 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2074
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2075 BootstrapTable.prototype.updateRows = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2076 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2077
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2078 this.$selectItem.each(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2079 that.data[$(this).data('index')][that.header.stateField] = $(this).prop('checked');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2080 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2081 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2082
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2083 BootstrapTable.prototype.resetRows = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2084 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2085
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2086 $.each(this.data, function (i, row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2087 that.$selectAll.prop('checked', false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2088 that.$selectItem.prop('checked', false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2089 if (that.header.stateField) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2090 row[that.header.stateField] = false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2091 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2092 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2093 this.initHiddenRows();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2094 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2095
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2096 BootstrapTable.prototype.trigger = function (name) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2097 var args = Array.prototype.slice.call(arguments, 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2098
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2099 name += '.bs.table';
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2100 this.options[BootstrapTable.EVENTS[name]].apply(this.options, args);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2101 this.$el.trigger($.Event(name), args);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2102
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2103 this.options.onAll(name, args);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2104 this.$el.trigger($.Event('all.bs.table'), [name, args]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2105 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2106
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2107 BootstrapTable.prototype.resetHeader = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2108 // fix #61: the hidden table reset header bug.
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2109 // fix bug: get $el.css('width') error sometime (height = 500)
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2110 clearTimeout(this.timeoutId_);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2111 this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2112 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2113
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2114 BootstrapTable.prototype.fitHeader = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2115 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2116 fixedBody,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2117 scrollWidth,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2118 focused,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2119 focusedTemp;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2120
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2121 if (that.$el.is(':hidden')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2122 that.timeoutId_ = setTimeout($.proxy(that.fitHeader, that), 100);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2123 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2124 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2125 fixedBody = this.$tableBody.get(0);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2126
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2127 scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth &&
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2128 fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2129 getScrollBarWidth() : 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2130
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2131 this.$el.css('margin-top', -this.$header.outerHeight());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2132
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2133 focused = $(':focus');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2134 if (focused.length > 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2135 var $th = focused.parents('th');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2136 if ($th.length > 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2137 var dataField = $th.attr('data-field');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2138 if (dataField !== undefined) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2139 var $headerTh = this.$header.find("[data-field='" + dataField + "']");
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2140 if ($headerTh.length > 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2141 $headerTh.find(":input").addClass("focus-temp");
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2142 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2143 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2144 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2145 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2146
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2147 this.$header_ = this.$header.clone(true, true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2148 this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2149 this.$tableHeader.css({
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2150 'margin-right': scrollWidth
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2151 }).find('table').css('width', this.$el.outerWidth())
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2152 .html('').attr('class', this.$el.attr('class'))
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2153 .append(this.$header_);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2154
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2155
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2156 focusedTemp = $('.focus-temp:visible:eq(0)');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2157 if (focusedTemp.length > 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2158 focusedTemp.focus();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2159 this.$header.find('.focus-temp').removeClass('focus-temp');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2160 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2161
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2162 // fix bug: $.data() is not working as expected after $.append()
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2163 this.$header.find('th[data-field]').each(function (i) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2164 that.$header_.find(sprintf('th[data-field="%s"]', $(this).data('field'))).data($(this).data());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2165 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2166
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2167 var visibleFields = this.getVisibleFields(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2168 $ths = this.$header_.find('th');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2169
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2170 this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2171 var $this = $(this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2172 index = i;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2173
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2174 if (that.options.detailView && !that.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2175 if (i === 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2176 that.$header_.find('th.detail').find('.fht-cell').width($this.innerWidth());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2177 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2178 index = i - 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2179 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2180
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2181 var $th = that.$header_.find(sprintf('th[data-field="%s"]', visibleFields[index]));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2182 if ($th.length > 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2183 $th = $($ths[$this[0].cellIndex]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2184 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2185
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2186 $th.find('.fht-cell').width($this.innerWidth());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2187 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2188 // horizontal scroll event
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2189 // TODO: it's probably better improving the layout than binding to scroll event
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2190 this.$tableBody.off('scroll').on('scroll', function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2191 that.$tableHeader.scrollLeft($(this).scrollLeft());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2192
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2193 if (that.options.showFooter && !that.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2194 that.$tableFooter.scrollLeft($(this).scrollLeft());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2195 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2196 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2197 that.trigger('post-header');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2198 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2199
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2200 BootstrapTable.prototype.resetFooter = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2201 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2202 data = that.getData(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2203 html = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2204
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2205 if (!this.options.showFooter || this.options.cardView) { //do nothing
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2206 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2207 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2208
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2209 if (!this.options.cardView && this.options.detailView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2210 html.push('<td><div class="th-inner">&nbsp;</div><div class="fht-cell"></div></td>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2211 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2212
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2213 $.each(this.columns, function (i, column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2214 var key,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2215 falign = '', // footer align style
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2216 valign = '',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2217 csses = [],
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2218 style = {},
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2219 class_ = sprintf(' class="%s"', column['class']);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2220
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2221 if (!column.visible) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2222 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2223 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2224
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2225 if (that.options.cardView && (!column.cardVisible)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2226 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2227 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2228
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2229 falign = sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2230 valign = sprintf('vertical-align: %s; ', column.valign);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2231
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2232 style = calculateObjectValue(null, that.options.footerStyle);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2233
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2234 if (style && style.css) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2235 for (key in style.css) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2236 csses.push(key + ': ' + style.css[key]);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2237 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2238 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2239
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2240 html.push('<td', class_, sprintf(' style="%s"', falign + valign + csses.concat().join('; ')), '>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2241 html.push('<div class="th-inner">');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2242
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2243 html.push(calculateObjectValue(column, column.footerFormatter, [data], '&nbsp;') || '&nbsp;');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2244
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2245 html.push('</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2246 html.push('<div class="fht-cell"></div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2247 html.push('</div>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2248 html.push('</td>');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2249 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2250
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2251 this.$tableFooter.find('tr').html(html.join(''));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2252 this.$tableFooter.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2253 clearTimeout(this.timeoutFooter_);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2254 this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2255 this.$el.is(':hidden') ? 100 : 0);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2256 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2257
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2258 BootstrapTable.prototype.fitFooter = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2259 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2260 $footerTd,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2261 elWidth,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2262 scrollWidth;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2263
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2264 clearTimeout(this.timeoutFooter_);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2265 if (this.$el.is(':hidden')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2266 this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2267 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2268 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2269
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2270 elWidth = this.$el.css('width');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2271 scrollWidth = elWidth > this.$tableBody.width() ? getScrollBarWidth() : 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2272
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2273 this.$tableFooter.css({
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2274 'margin-right': scrollWidth
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2275 }).find('table').css('width', elWidth)
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2276 .attr('class', this.$el.attr('class'));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2277
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2278 $footerTd = this.$tableFooter.find('td');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2279
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2280 this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2281 var $this = $(this);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2282
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2283 $footerTd.eq(i).find('.fht-cell').width($this.innerWidth());
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2284 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2285 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2286
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2287 BootstrapTable.prototype.toggleColumn = function (index, checked, needUpdate) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2288 if (index === -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2289 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2290 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2291 this.columns[index].visible = checked;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2292 this.initHeader();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2293 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2294 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2295 this.initBody();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2296
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2297 if (this.options.showColumns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2298 var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2299
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2300 if (needUpdate) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2301 $items.filter(sprintf('[value="%s"]', index)).prop('checked', checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2302 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2303
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2304 if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2305 $items.filter(':checked').prop('disabled', true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2306 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2307 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2308 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2309
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2310 BootstrapTable.prototype.getVisibleFields = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2311 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2312 visibleFields = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2313
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2314 $.each(this.header.fields, function (j, field) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2315 var column = that.columns[getFieldIndex(that.columns, field)];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2316
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2317 if (!column.visible) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2318 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2319 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2320 visibleFields.push(field);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2321 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2322 return visibleFields;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2323 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2324
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2325 // PUBLIC FUNCTION DEFINITION
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2326 // =======================
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2327
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2328 BootstrapTable.prototype.resetView = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2329 var padding = 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2330
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2331 if (params && params.height) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2332 this.options.height = params.height;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2333 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2334
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2335 this.$selectAll.prop('checked', this.$selectItem.length > 0 &&
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2336 this.$selectItem.length === this.$selectItem.filter(':checked').length);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2337
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2338 if (this.options.height) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2339 var toolbarHeight = this.$toolbar.outerHeight(true),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2340 paginationHeight = this.$pagination.outerHeight(true),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2341 height = this.options.height - toolbarHeight - paginationHeight;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2342
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2343 this.$tableContainer.css('height', height + 'px');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2344 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2345
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2346 if (this.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2347 // remove the element css
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2348 this.$el.css('margin-top', '0');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2349 this.$tableContainer.css('padding-bottom', '0');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2350 this.$tableFooter.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2351 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2352 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2353
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2354 if (this.options.showHeader && this.options.height) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2355 this.$tableHeader.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2356 this.resetHeader();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2357 padding += this.$header.outerHeight();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2358 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2359 this.$tableHeader.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2360 this.trigger('post-header');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2361 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2362
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2363 if (this.options.showFooter) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2364 this.resetFooter();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2365 if (this.options.height) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2366 padding += this.$tableFooter.outerHeight() + 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2367 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2368 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2369
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2370 // Assign the correct sortable arrow
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2371 this.getCaret();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2372 this.$tableContainer.css('padding-bottom', padding + 'px');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2373 this.trigger('reset-view');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2374 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2375
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2376 BootstrapTable.prototype.getData = function (useCurrentPage) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2377 return (this.searchText || !$.isEmptyObject(this.filterColumns) || !$.isEmptyObject(this.filterColumnsPartial)) ?
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2378 (useCurrentPage ? this.data.slice(this.pageFrom - 1, this.pageTo) : this.data) :
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2379 (useCurrentPage ? this.options.data.slice(this.pageFrom - 1, this.pageTo) : this.options.data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2380 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2381
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2382 BootstrapTable.prototype.load = function (data) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2383 var fixedScroll = false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2384
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2385 // #431: support pagination
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2386 if (this.options.sidePagination === 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2387 this.options.totalRows = data[this.options.totalField];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2388 fixedScroll = data.fixedScroll;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2389 data = data[this.options.dataField];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2390 } else if (!$.isArray(data)) { // support fixedScroll
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2391 fixedScroll = data.fixedScroll;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2392 data = data.data;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2393 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2394
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2395 this.initData(data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2396 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2397 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2398 this.initBody(fixedScroll);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2399 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2400
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2401 BootstrapTable.prototype.append = function (data) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2402 this.initData(data, 'append');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2403 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2404 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2405 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2406 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2407 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2408
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2409 BootstrapTable.prototype.prepend = function (data) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2410 this.initData(data, 'prepend');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2411 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2412 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2413 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2414 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2415 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2416
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2417 BootstrapTable.prototype.remove = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2418 var len = this.options.data.length,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2419 i, row;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2420
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2421 if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2422 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2423 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2424
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2425 for (i = len - 1; i >= 0; i--) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2426 row = this.options.data[i];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2427
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2428 if (!row.hasOwnProperty(params.field)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2429 continue;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2430 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2431 if ($.inArray(row[params.field], params.values) !== -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2432 this.options.data.splice(i, 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2433 if (this.options.sidePagination === 'server') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2434 this.options.totalRows -= 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2435 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2436 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2437 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2438
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2439 if (len === this.options.data.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2440 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2441 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2442
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2443 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2444 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2445 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2446 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2447 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2448
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2449 BootstrapTable.prototype.removeAll = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2450 if (this.options.data.length > 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2451 this.options.data.splice(0, this.options.data.length);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2452 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2453 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2454 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2455 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2456 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2457
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2458 BootstrapTable.prototype.getRowByUniqueId = function (id) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2459 var uniqueId = this.options.uniqueId,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2460 len = this.options.data.length,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2461 dataRow = null,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2462 i, row, rowUniqueId;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2463
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2464 for (i = len - 1; i >= 0; i--) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2465 row = this.options.data[i];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2466
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2467 if (row.hasOwnProperty(uniqueId)) { // uniqueId is a column
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2468 rowUniqueId = row[uniqueId];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2469 } else if(row._data.hasOwnProperty(uniqueId)) { // uniqueId is a row data property
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2470 rowUniqueId = row._data[uniqueId];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2471 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2472 continue;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2473 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2474
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2475 if (typeof rowUniqueId === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2476 id = id.toString();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2477 } else if (typeof rowUniqueId === 'number') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2478 if ((Number(rowUniqueId) === rowUniqueId) && (rowUniqueId % 1 === 0)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2479 id = parseInt(id);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2480 } else if ((rowUniqueId === Number(rowUniqueId)) && (rowUniqueId !== 0)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2481 id = parseFloat(id);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2482 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2483 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2484
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2485 if (rowUniqueId === id) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2486 dataRow = row;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2487 break;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2488 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2489 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2490
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2491 return dataRow;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2492 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2493
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2494 BootstrapTable.prototype.removeByUniqueId = function (id) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2495 var len = this.options.data.length,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2496 row = this.getRowByUniqueId(id);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2497
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2498 if (row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2499 this.options.data.splice(this.options.data.indexOf(row), 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2500 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2501
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2502 if (len === this.options.data.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2503 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2504 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2505
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2506 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2507 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2508 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2509 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2510
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2511 BootstrapTable.prototype.updateByUniqueId = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2512 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2513 var allParams = $.isArray(params) ? params : [ params ];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2514
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2515 $.each(allParams, function(i, params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2516 var rowId;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2517
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2518 if (!params.hasOwnProperty('id') || !params.hasOwnProperty('row')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2519 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2520 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2521
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2522 rowId = $.inArray(that.getRowByUniqueId(params.id), that.options.data);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2523
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2524 if (rowId === -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2525 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2526 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2527 $.extend(that.options.data[rowId], params.row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2528 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2529
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2530 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2531 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2532 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2533 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2534 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2535
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2536 BootstrapTable.prototype.insertRow = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2537 if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2538 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2539 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2540 this.data.splice(params.index, 0, params.row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2541 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2542 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2543 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2544 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2545 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2546
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2547 BootstrapTable.prototype.updateRow = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2548 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2549 var allParams = $.isArray(params) ? params : [ params ];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2550
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2551 $.each(allParams, function(i, params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2552 if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2553 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2554 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2555 $.extend(that.options.data[params.index], params.row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2556 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2557
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2558 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2559 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2560 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2561 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2562 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2563
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2564 BootstrapTable.prototype.initHiddenRows = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2565 this.hiddenRows = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2566 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2567
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2568 BootstrapTable.prototype.showRow = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2569 this.toggleRow(params, true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2570 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2571
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2572 BootstrapTable.prototype.hideRow = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2573 this.toggleRow(params, false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2574 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2575
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2576 BootstrapTable.prototype.toggleRow = function (params, visible) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2577 var row, index;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2578
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2579 if (params.hasOwnProperty('index')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2580 row = this.getData()[params.index];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2581 } else if (params.hasOwnProperty('uniqueId')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2582 row = this.getRowByUniqueId(params.uniqueId);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2583 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2584
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2585 if (!row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2586 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2587 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2588
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2589 index = $.inArray(row, this.hiddenRows);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2590
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2591 if (!visible && index === -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2592 this.hiddenRows.push(row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2593 } else if (visible && index > -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2594 this.hiddenRows.splice(index, 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2595 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2596 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2597 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2598
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2599 BootstrapTable.prototype.getHiddenRows = function (show) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2600 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2601 data = this.getData(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2602 rows = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2603
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2604 $.each(data, function (i, row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2605 if ($.inArray(row, that.hiddenRows) > -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2606 rows.push(row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2607 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2608 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2609 this.hiddenRows = rows;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2610 return rows;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2611 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2612
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2613 BootstrapTable.prototype.mergeCells = function (options) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2614 var row = options.index,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2615 col = $.inArray(options.field, this.getVisibleFields()),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2616 rowspan = options.rowspan || 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2617 colspan = options.colspan || 1,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2618 i, j,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2619 $tr = this.$body.find('>tr'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2620 $td;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2621
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2622 if (this.options.detailView && !this.options.cardView) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2623 col += 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2624 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2625
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2626 $td = $tr.eq(row).find('>td').eq(col);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2627
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2628 if (row < 0 || col < 0 || row >= this.data.length) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2629 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2630 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2631
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2632 for (i = row; i < row + rowspan; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2633 for (j = col; j < col + colspan; j++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2634 $tr.eq(i).find('>td').eq(j).hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2635 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2636 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2637
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2638 $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2639 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2640
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2641 BootstrapTable.prototype.updateCell = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2642 if (!params.hasOwnProperty('index') ||
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2643 !params.hasOwnProperty('field') ||
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2644 !params.hasOwnProperty('value')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2645 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2646 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2647 this.data[params.index][params.field] = params.value;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2648
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2649 if (params.reinit === false) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2650 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2651 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2652 this.initSort();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2653 this.initBody(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2654 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2655
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2656 BootstrapTable.prototype.getOptions = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2657 return this.options;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2658 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2659
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2660 BootstrapTable.prototype.getSelections = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2661 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2662
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2663 return $.grep(this.options.data, function (row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2664 // fix #2424: from html with checkbox
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2665 return row[that.header.stateField] === true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2666 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2667 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2668
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2669 BootstrapTable.prototype.getAllSelections = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2670 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2671
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2672 return $.grep(this.options.data, function (row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2673 return row[that.header.stateField];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2674 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2675 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2676
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2677 BootstrapTable.prototype.checkAll = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2678 this.checkAll_(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2679 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2680
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2681 BootstrapTable.prototype.uncheckAll = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2682 this.checkAll_(false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2683 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2684
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2685 BootstrapTable.prototype.checkInvert = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2686 var that = this;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2687 var rows = that.$selectItem.filter(':enabled');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2688 var checked = rows.filter(':checked');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2689 rows.each(function() {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2690 $(this).prop('checked', !$(this).prop('checked'));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2691 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2692 that.updateRows();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2693 that.updateSelected();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2694 that.trigger('uncheck-some', checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2695 checked = that.getSelections();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2696 that.trigger('check-some', checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2697 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2698
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2699 BootstrapTable.prototype.checkAll_ = function (checked) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2700 var rows;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2701 if (!checked) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2702 rows = this.getSelections();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2703 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2704 this.$selectAll.add(this.$selectAll_).prop('checked', checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2705 this.$selectItem.filter(':enabled').prop('checked', checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2706 this.updateRows();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2707 if (checked) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2708 rows = this.getSelections();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2709 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2710 this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2711 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2712
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2713 BootstrapTable.prototype.check = function (index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2714 this.check_(true, index);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2715 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2716
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2717 BootstrapTable.prototype.uncheck = function (index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2718 this.check_(false, index);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2719 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2720
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2721 BootstrapTable.prototype.check_ = function (checked, index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2722 var $el = this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2723 this.data[index][this.header.stateField] = checked;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2724 this.updateSelected();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2725 this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2726 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2727
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2728 BootstrapTable.prototype.checkBy = function (obj) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2729 this.checkBy_(true, obj);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2730 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2731
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2732 BootstrapTable.prototype.uncheckBy = function (obj) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2733 this.checkBy_(false, obj);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2734 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2735
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2736 BootstrapTable.prototype.checkBy_ = function (checked, obj) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2737 if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2738 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2739 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2740
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2741 var that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2742 rows = [];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2743 $.each(this.options.data, function (index, row) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2744 if (!row.hasOwnProperty(obj.field)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2745 return false;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2746 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2747 if ($.inArray(row[obj.field], obj.values) !== -1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2748 var $el = that.$selectItem.filter(':enabled')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2749 .filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2750 row[that.header.stateField] = checked;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2751 rows.push(row);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2752 that.trigger(checked ? 'check' : 'uncheck', row, $el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2753 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2754 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2755 this.updateSelected();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2756 this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2757 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2758
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2759 BootstrapTable.prototype.destroy = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2760 this.$el.insertBefore(this.$container);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2761 $(this.options.toolbar).insertBefore(this.$el);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2762 this.$container.next().remove();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2763 this.$container.remove();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2764 this.$el.html(this.$el_.html())
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2765 .css('margin-top', '0')
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2766 .attr('class', this.$el_.attr('class') || ''); // reset the class
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2767 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2768
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2769 BootstrapTable.prototype.showLoading = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2770 this.$tableLoading.show();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2771 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2772
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2773 BootstrapTable.prototype.hideLoading = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2774 this.$tableLoading.hide();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2775 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2776
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2777 BootstrapTable.prototype.togglePagination = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2778 this.options.pagination = !this.options.pagination;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2779 var button = this.$toolbar.find('button[name="paginationSwitch"] i');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2780 if (this.options.pagination) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2781 button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchDown);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2782 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2783 button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchUp);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2784 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2785 this.updatePagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2786 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2787
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2788 BootstrapTable.prototype.refresh = function (params) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2789 if (params && params.url) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2790 this.options.url = params.url;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2791 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2792 if (params && params.pageNumber) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2793 this.options.pageNumber = params.pageNumber;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2794 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2795 if (params && params.pageSize) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2796 this.options.pageSize = params.pageSize;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2797 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2798 this.initServer(params && params.silent,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2799 params && params.query, params && params.url);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2800 this.trigger('refresh', params);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2801 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2802
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2803 BootstrapTable.prototype.resetWidth = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2804 if (this.options.showHeader && this.options.height) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2805 this.fitHeader();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2806 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2807 if (this.options.showFooter) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2808 this.fitFooter();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2809 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2810 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2811
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2812 BootstrapTable.prototype.showColumn = function (field) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2813 this.toggleColumn(getFieldIndex(this.columns, field), true, true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2814 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2815
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2816 BootstrapTable.prototype.hideColumn = function (field) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2817 this.toggleColumn(getFieldIndex(this.columns, field), false, true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2818 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2819
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2820 BootstrapTable.prototype.getHiddenColumns = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2821 return $.grep(this.columns, function (column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2822 return !column.visible;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2823 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2824 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2825
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2826 BootstrapTable.prototype.getVisibleColumns = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2827 return $.grep(this.columns, function (column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2828 return column.visible;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2829 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2830 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2831
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2832 BootstrapTable.prototype.toggleAllColumns = function (visible) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2833 $.each(this.columns, function (i, column) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2834 this.columns[i].visible = visible;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2835 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2836
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2837 this.initHeader();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2838 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2839 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2840 this.initBody();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2841 if (this.options.showColumns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2842 var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2843
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2844 if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2845 $items.filter(':checked').prop('disabled', true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2846 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2847 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2848 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2849
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2850 BootstrapTable.prototype.showAllColumns = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2851 this.toggleAllColumns(true);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2852 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2853
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2854 BootstrapTable.prototype.hideAllColumns = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2855 this.toggleAllColumns(false);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2856 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2857
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2858 BootstrapTable.prototype.filterBy = function (columns) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2859 this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2860 this.options.pageNumber = 1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2861 this.initSearch();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2862 this.updatePagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2863 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2864
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2865 BootstrapTable.prototype.scrollTo = function (value) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2866 if (typeof value === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2867 value = value === 'bottom' ? this.$tableBody[0].scrollHeight : 0;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2868 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2869 if (typeof value === 'number') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2870 this.$tableBody.scrollTop(value);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2871 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2872 if (typeof value === 'undefined') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2873 return this.$tableBody.scrollTop();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2874 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2875 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2876
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2877 BootstrapTable.prototype.getScrollPosition = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2878 return this.scrollTo();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2879 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2880
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2881 BootstrapTable.prototype.selectPage = function (page) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2882 if (page > 0 && page <= this.options.totalPages) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2883 this.options.pageNumber = page;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2884 this.updatePagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2885 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2886 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2887
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2888 BootstrapTable.prototype.prevPage = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2889 if (this.options.pageNumber > 1) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2890 this.options.pageNumber--;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2891 this.updatePagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2892 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2893 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2894
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2895 BootstrapTable.prototype.nextPage = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2896 if (this.options.pageNumber < this.options.totalPages) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2897 this.options.pageNumber++;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2898 this.updatePagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2899 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2900 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2901
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2902 BootstrapTable.prototype.toggleView = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2903 this.options.cardView = !this.options.cardView;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2904 this.initHeader();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2905 // Fixed remove toolbar when click cardView button.
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2906 //that.initToolbar();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2907 this.initBody();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2908 this.trigger('toggle', this.options.cardView);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2909 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2910
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2911 BootstrapTable.prototype.refreshOptions = function (options) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2912 //If the objects are equivalent then avoid the call of destroy / init methods
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2913 if (compareObjects(this.options, options, true)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2914 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2915 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2916 this.options = $.extend(this.options, options);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2917 this.trigger('refresh-options', this.options);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2918 this.destroy();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2919 this.init();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2920 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2921
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2922 BootstrapTable.prototype.resetSearch = function (text) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2923 var $search = this.$toolbar.find('.search input');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2924 $search.val(text || '');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2925 this.onSearch({currentTarget: $search});
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2926 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2927
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2928 BootstrapTable.prototype.expandRow_ = function (expand, index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2929 var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', index));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2930 if ($tr.next().is('tr.detail-view') === (expand ? false : true)) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2931 $tr.find('> td > .detail-icon').click();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2932 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2933 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2934
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2935 BootstrapTable.prototype.expandRow = function (index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2936 this.expandRow_(true, index);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2937 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2938
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2939 BootstrapTable.prototype.collapseRow = function (index) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2940 this.expandRow_(false, index);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2941 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2942
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2943 BootstrapTable.prototype.expandAllRows = function (isSubTable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2944 if (isSubTable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2945 var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', 0)),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2946 that = this,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2947 detailIcon = null,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2948 executeInterval = false,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2949 idInterval = -1;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2950
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2951 if (!$tr.next().is('tr.detail-view')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2952 $tr.find('> td > .detail-icon').click();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2953 executeInterval = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2954 } else if (!$tr.next().next().is('tr.detail-view')) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2955 $tr.next().find(".detail-icon").click();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2956 executeInterval = true;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2957 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2958
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2959 if (executeInterval) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2960 try {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2961 idInterval = setInterval(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2962 detailIcon = that.$body.find("tr.detail-view").last().find(".detail-icon");
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2963 if (detailIcon.length > 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2964 detailIcon.click();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2965 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2966 clearInterval(idInterval);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2967 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2968 }, 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2969 } catch (ex) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2970 clearInterval(idInterval);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2971 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2972 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2973 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2974 var trs = this.$body.children();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2975 for (var i = 0; i < trs.length; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2976 this.expandRow_(true, $(trs[i]).data("index"));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2977 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2978 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2979 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2980
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2981 BootstrapTable.prototype.collapseAllRows = function (isSubTable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2982 if (isSubTable) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2983 this.expandRow_(false, 0);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2984 } else {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2985 var trs = this.$body.children();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2986 for (var i = 0; i < trs.length; i++) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2987 this.expandRow_(false, $(trs[i]).data("index"));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2988 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2989 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2990 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2991
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2992 BootstrapTable.prototype.updateFormatText = function (name, text) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2993 if (this.options[sprintf('format%s', name)]) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2994 if (typeof text === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2995 this.options[sprintf('format%s', name)] = function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2996 return text;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2997 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2998 } else if (typeof text === 'function') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
2999 this.options[sprintf('format%s', name)] = text;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3000 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3001 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3002 this.initToolbar();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3003 this.initPagination();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3004 this.initBody();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3005 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3006
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3007 // BOOTSTRAP TABLE PLUGIN DEFINITION
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3008 // =======================
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3009
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3010 var allowedMethods = [
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3011 'getOptions',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3012 'getSelections', 'getAllSelections', 'getData',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3013 'load', 'append', 'prepend', 'remove', 'removeAll',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3014 'insertRow', 'updateRow', 'updateCell', 'updateByUniqueId', 'removeByUniqueId',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3015 'getRowByUniqueId', 'showRow', 'hideRow', 'getHiddenRows',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3016 'mergeCells',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3017 'checkAll', 'uncheckAll', 'checkInvert',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3018 'check', 'uncheck',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3019 'checkBy', 'uncheckBy',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3020 'refresh',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3021 'resetView',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3022 'resetWidth',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3023 'destroy',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3024 'showLoading', 'hideLoading',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3025 'showColumn', 'hideColumn', 'getHiddenColumns', 'getVisibleColumns',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3026 'showAllColumns', 'hideAllColumns',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3027 'filterBy',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3028 'scrollTo',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3029 'getScrollPosition',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3030 'selectPage', 'prevPage', 'nextPage',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3031 'togglePagination',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3032 'toggleView',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3033 'refreshOptions',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3034 'resetSearch',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3035 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows',
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3036 'updateFormatText'
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3037 ];
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3038
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3039 $.fn.bootstrapTable = function (option) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3040 var value,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3041 args = Array.prototype.slice.call(arguments, 1);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3042
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3043 this.each(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3044 var $this = $(this),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3045 data = $this.data('bootstrap.table'),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3046 options = $.extend({}, BootstrapTable.DEFAULTS, $this.data(),
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3047 typeof option === 'object' && option);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3048
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3049 if (typeof option === 'string') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3050 if ($.inArray(option, allowedMethods) < 0) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3051 throw new Error("Unknown method: " + option);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3052 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3053
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3054 if (!data) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3055 return;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3056 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3057
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3058 value = data[option].apply(data, args);
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3059
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3060 if (option === 'destroy') {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3061 $this.removeData('bootstrap.table');
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3062 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3063 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3064
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3065 if (!data) {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3066 $this.data('bootstrap.table', (data = new BootstrapTable(this, options)));
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3067 }
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3068 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3069
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3070 return typeof value === 'undefined' ? this : value;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3071 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3072
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3073 $.fn.bootstrapTable.Constructor = BootstrapTable;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3074 $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3075 $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3076 $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3077 $.fn.bootstrapTable.methods = allowedMethods;
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3078 $.fn.bootstrapTable.utils = {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3079 sprintf: sprintf,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3080 getFieldIndex: getFieldIndex,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3081 compareObjects: compareObjects,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3082 calculateObjectValue: calculateObjectValue,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3083 getItemField: getItemField,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3084 objectKeys: objectKeys,
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3085 isIEBrowser: isIEBrowser
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3086 };
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3087
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3088 // BOOTSTRAP TABLE INIT
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3089 // =======================
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3090
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3091 $(function () {
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3092 $('[data-toggle="table"]').bootstrapTable();
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3093 });
4bc00caa60b4 Uploaded
pierre.pouchin
parents: 1
diff changeset
3094 })(jQuery);