annotate bin/js/bootstrap-table.js @ 6:518b780b8aa5 draft

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