annotate bin/js/bootstrap-table.js @ 8:c61e7cc135c2 draft

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