forked from jeffdupont/bootstrap-data-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-datatable.js
1155 lines (949 loc) · 32.6 KB
/
bootstrap-datatable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* Bootstrap Data Table Plugin v1.5.5
*
* Author: Jeff Dupont
* ==========================================================
* Copyright 2012
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ==========================================================
*/
;(function( $ ){
/* DATATABLE CLASS DEFINITION
* ========================== */
var DataTable = function ( element, options ) {
this.$element = $(element);
this.options = options;
this.enabled = true;
this.columns = [];
this.rows = [];
this.buttons = [];
// this needs to be handled better
this.localStorageId = "datatable_" + (options.id || options.url.replace(/\W/ig, '_'));
// set the defaults for the column options array
for(var column in this.options.columns) {
// check sortable
if(typeof this.options.columns[column].sortable === undefined)
this.options.columns[column].sortable = true;
}
this.$default = this.$element.children().length ?
this.$element.children() :
$("<div></div>")
.addClass("alert alert-error")
.html("No Results Found");
this.$element.addClass("clearfix");
// clear out the localStorage for this entry
if(localStorage) {
localStorage[this.localStorageId] = 'false';
}
if(this.options.tablePreRender && typeof this.options.tablePreRender === 'function')
this.options.tablePreRender.call(this)
// initialize the toolbar
_initToolbar.call(this)
if(this.options.autoLoad === true) this.render();
};
DataTable.prototype = {
constructor: DataTable
, render: function () {
var o = this.options
, $e = this.$element;
// show loading
this.loading( true );
// reset the columns and rows
this.columns = [];
this.rows = [];
this.buttons = [];
this.$wrapper = undefined;
this.$table = undefined;
this.$header = undefined;
this.$body = undefined;
this.$footer = undefined;
this.$pagination = undefined;
if(this.$toolbar) this.$toolbar.remove();
// top
this.$top_details = $("<div></div>")
.attr("id", "dt-top-details");
// bottom
this.$bottom_details = $("<div></div>")
.attr("id", "dt-bottom-details");
// localize the object
var that = this;
// pull in the data from the ajax call
if(o.url !== "") {
$.ajax({
url: o.url
, type: "POST"
, dataType: "json"
, data: $.extend({}, o.post, {
currentPage: o.currentPage
, perPage: o.perPage
, sort: o.sort
, filter: o.filter
})
, success: function( res ) {
if(o.debug) console.log(res);
that.resultset = res;
if(!res || res === undefined || !res.data || res.data.length == 0) {
showError.call(that);
return;
}
// clear out the current elements in the container
$e.empty();
// set the sort and filter configuration
o.sort = res.sort;
o.filter = res.filter;
o.totalRows = res.totalRows;
// set the current page if we're forcing it from the server
if(res.currentPage) o.currentPage = parseInt(res.currentPage);
// retrieve the saved columns
_retrieveColumns.call(that, localStorage[that.localStorageId])
// append the table
$e.append(that.table());
// append the detail boxes
$e.prepend(that.$top_details);
$e.append(that.$bottom_details);
// render the rest of the table
if(o.showHeader) that.header();
if(o.showFooter) that.footer();
// fill in the table body
that.body();
// render the pagination
if(o.showTopPagination && that.pagination())
that.$top_details.append(that.pagination().clone(true));
if(o.showPagination && that.pagination())
that.$bottom_details.append(that.pagination().clone(true));
// update the details for the results
that.details();
// initialize the toolbar
_initToolbar.call(that);
// nearly complete... let the user apply any final adjustments
if(o.tableCallback && typeof o.tableCallback === 'function')
o.tableCallback.call(that);
that.loading( false );
}
, error: function( e ) {
if(o.debug) console.log(e);
showError.call(that);
that.loading( false );
}
});
}
}
, loading: function ( show ) {
var $e = this.$element;
if(!this.$loading) {
this.$loading = $("<div></div>")
.css({
position: 'absolute'
, top: parseInt($e.position().top) + 5
, left: parseInt($e.position().left) + parseInt($e.css("marginLeft")) + Math.floor($e.width() / 4)
, width: Math.floor($e.width() / 2) + "px"
})
.append(
$("<div></div>")
.addClass("progress progress-striped active")
.append($('<div class="bar" style="width: 100%"></div>'))
)
.appendTo(document.body)
}
if(show) {
$e.css({ opacity: 0.2 });
}
else {
$e.css({ opacity: 1 });
this.$loading.remove();
this.$loading = undefined;
}
}
, toolbar: function () {
var o = this.options
, $e = this.$element
, that = this;
this.$toolbar = $("<div></div>")
.addClass("dt-toolbar btn-toolbar pull-right");
this.$button_group = $("<div></div>")
.addClass("btn-group")
.appendTo(this.$toolbar);
// add all the custom buttons
for(var i = 0; i < o.buttons.length; i++) {
this.buttons.push(o.buttons[i]);
}
// attach all buttons to the toolbar
$.each(this.buttons, function() {
that.$button_group.append(this);
});
// attach the toolbar to the section header
if(o.sectionHeader) {
this.$section_header = $(o.sectionHeader);
this.$section_header.append(this.$toolbar);
}
else if(o.title !== '' && !this.$section_header) {
this.$section_header = $("<h2></h2>")
.text(o.title)
.append(this.$toolbar);
$e.before(this.$section_header);
}
else {
if(!this.$toolbar_container) {
this.$toolbar_container = $("<div></div>")
.addClass('dt-toolbar-container clearfix')
}
$e.prepend(
this.$toolbar_container
.append(this.$toolbar)
);
}
return this.$toolbar;
}
, details: function () {
var o = this.options
, res = this.resultset
, start = 0
, end = 0
, that = this;
start = (o.currentPage * o.perPage) - o.perPage + 1
if(start < 1) start = 1;
end = (o.currentPage * o.perPage);
if(end > o.totalRows) end = o.totalRows;
$('<div class="pull-left"><p>Showing ' + start + ' to ' + end + ' of ' + o.totalRows + ' rows</p></div>')
.prependTo(this.$bottom_details);
}
, table: function () {
var $e = this.$element
, o = this.options;
if(!this.$table_wrapper) {
this.$wrapper = $("<div></div>")
.addClass("dt-table-wrapper");
}
if (!this.$table) {
this.$table = $('<table></table>')
.addClass(o.class);
}
this.$wrapper.append(this.$table);
return this.$wrapper;
}
, header: function () {
var o = this.options
, res = this.resultset;
if(!this.$header) {
this.$header = $('<thead></thead>');
var row = $('<tr></tr>');
// loop through the columns
for(var column in o.columns) {
var $cell = this.column(column)
, colprop = $cell.data("column_properties");
// attach the sort click event
if(colprop.sortable && !colprop.custom)
$cell.click(this, this.sort)
.css({'cursor':'pointer'});
for(var i = 0; i < o.sort.length; i++) {
if(o.sort[i][0] == colprop.field) {
if(o.sort[i][1] == "asc") {
$cell.append($(o.ascending));
colprop.sortOrder = "asc";
}
else if(o.sort[i][1] == "desc") {
$cell.append($(o.descending));
colprop.sortOrder = "desc";
}
}
}
row.append($cell);
this.$header.append(row);
this.columns.push($cell);
}
// any final user adjustments to the header
if(o.headerCallback && typeof o.headerCallback === 'function')
o.headerCallback.call(this);
this.$table
.append(this.$header);
}
return this.$header;
}
, footer: function () {
var o = this.options
, res = this.resultset
if(!this.$footer) {
this.$footer = $('<tfoot></tfoot>');
// loop through the columns
for(column in o.columns) {
var $cell = $('<td></td>')
$cell
.data("cell_properties", o.columns[column])
.addClass(o.columns[column].classname)
this.$footer.append($cell);
}
// any final user adjustments to the footer
if(o.footerCallback && typeof o.footerCallback === 'function')
o.footerCallback.call(this, this.resultset.footer)
this.$table
.append(this.$footer);
}
return this.$footer;
}
, body: function () {
var res = this.resultset
, o = this.options;
if(!this.$body) {
this.$body = $('<tbody></tbody>');
// loop through the results
for(var i = 0; i < res.data.length; i++) {
var row = this.row(res.data[i]);
this.$body.append(row);
this.rows.push(row);
}
if(o.showFilterRow) this.$body.prepend(this.filter());
this.$table
.append(this.$body);
}
return this.$body;
}
, filter: function () {
var $row = $("<tr></tr>")
, o = this.options
, that = this;
$row.addClass("dt-filter-row");
// loop through the columns
for(var column in o.columns) {
var $cell = $("<td></td>")
.addClass(o.columns[column].classname);
if(o.columns[column].hidden) $cell.hide();
if(o.columns[column].filter && o.columns[column].field) {
$cell
.append(
$("<input/>")
.attr("name", "filter_" + o.columns[column].field)
.data("filter", o.columns[column].field)
.val(o.filter[o.columns[column].field] || "")
// .change(this, this.runFilter)
.change(function(e){
runFilter.call(this, that);
})
);
}
$row.append($cell);
}
return $row;
}
, row: function ( rowdata ) {
var $row = $("<tr></tr>")
, o = this.options;
// loop through the columns
for(var column in o.columns) {
var cell = this.cell( rowdata, column );
$row.append(cell);
}
// callback for postprocessing on the row
if(o.rowCallback && typeof o.rowCallback === "function")
$row = o.rowCallback( $row, rowdata );
return $row;
}
, cell: function ( data, column ) {
var celldata = data[this.options.columns[column].field] || this.options.columns[column].custom
, $cell = $('<td></td>')
, o = this.options;
// preprocess on the cell data for a column
if(o.columns[column].callback && typeof o.columns[column].callback === "function")
celldata = o.columns[column].callback.call( $cell, data, o.columns[column] )
$cell
.data("cell_properties", o.columns[column])
.addClass(o.columns[column].classname)
.append(celldata || " ")
if(o.columns[column].css) $cell.css(o.columns[column].css);
if(o.columns[column].hidden) $cell.hide();
return $cell;
}
, column: function ( column ) {
var $cell = $('<th></th>')
, o = this.options
, classname = "dt-column_" + column + Math.floor((Math.random()*1000)+1);
o.columns[column].classname = classname;
$cell
.data("column_properties", o.columns[column])
.addClass(classname)
.text(o.columns[column].title);
if(o.columns[column].css) $cell.css(o.columns[column].css);
if(o.columns[column].hidden) $cell.hide();
return $cell;
}
, sort: function ( e ) {
var colprop = $(this).data("column_properties")
, that = e.data
, o = e.data.options
, found = false;
colprop.sortOrder = colprop.sortOrder ? (colprop.sortOrder == "asc" ? "desc" : "") : "asc";
if(o.allowMultipleSort) {
// does the sort already exist?
for(var i = 0; i < o.sort.length; i++) {
if(o.sort[i][0] == colprop.field) {
o.sort[i][1] = colprop.sortOrder;
if(colprop.sortOrder === "") o.sort.splice(i,1);
found = true;
}
}
if(!found) o.sort.push([colprop.field, colprop.sortOrder]);
}
else {
// clear out any current sorts
o.sort = [];
o.sort.push([colprop.field, colprop.sortOrder]);
}
if(o.debug) console.log(o.sort);
that.render();
}
, pagination: function () {
var $e = this.$element
, that = this
, o = this.options
, res = this.resultset;
// no paging needed
if(o.perPage >= res.totalRows) return;
if(!this.$pagination) {
this.$pagination = $("<div></div>");
// how many pages?
o.pageCount = Math.ceil(res.totalRows / o.perPage);
// setup the pager container and the quick page buttons
var $pager = $("<ul></ul>").addClass("pagination pagination-right")
, $first = $("<li></li>").append(
$("<a></a>")
.attr("href", "#")
.data("page", 1)
.html("← First")
.click(function() {
o.currentPage = 1
that.render();
return false;
})
)
, $previous = $("<li></li>").append(
$("<a></a>")
.attr("href", "#")
.data("page", o.currentPage - 1)
.text("Prev")
.click(function() {
o.currentPage -= 1
o.currentPage = o.currentPage >= 1 ? o.currentPage : 1
that.render();
return false;
})
)
, $next = $("<li></li>").append(
$("<a></a>")
.attr("href", "#")
.data("page", o.currentPage + 1)
.text("Next")
.click(function() {
o.currentPage += 1
o.currentPage = o.currentPage <= o.pageCount? o.currentPage : o.pageCount
that.render();
return false;
})
)
, $last = $("<li></li>").append(
$("<a></a>")
.attr("href", "#")
.data("page", o.pageCount)
.html("Last →")
.click(function() {
o.currentPage = o.pageCount
that.render();
return false;
})
);
var totalPages = o.pagePadding * 2
, start
, end;
if(totalPages >= o.pageCount) {
start = 1;
end = o.pageCount;
}
else {
start = o.currentPage - o.pagePadding;
if(start <= 0) start = 1;
end = start + totalPages;
if(end > o.pageCount) {
end = o.pageCount;
start = end - totalPages;
}
}
// append the pagination links
for(var i = start; i <= end; i++) {
var $link = $("<li></li>")
.append(
$("<a></a>")
.attr("href", "#")
.data("page", i)
.text(i)
.click(function() {
o.currentPage = $(this).data('page')
that.render();
return false;
})
);
if(i == o.currentPage) $link.addClass("active");
$pager.append($link);
}
// append quick jump buttons
if(o.currentPage == 1) {
$first.addClass("disabled");
$previous.addClass("disabled");
}
if(o.currentPage == o.pageCount) {
$next.addClass("disabled");
$last.addClass("disabled");
}
$pager.prepend($first, $previous);
$pager.append($next, $last);
this.$pagination.append($pager);
}
return this.$pagination;
}
, remove: function() {
var $e = this.$element
if(this.$section_header) this.$section_header.remove();
$e.data("datatable", null);
$e.empty();
}
};
/* DATATABLE PRIVATE METHODS
* ========================= */
function _initToolbar() {
var o = this.options;
// create the perpage dropdown
_initPerPage.call(this);
// handle filter options
if(o.filterModal) _initFilterModal.call(this);
// handle the column management
if(o.toggleColumns) _initColumnModal.call(this);
// handle the overflow option
if(o.allowOverflow) _initOverflowToggle.call(this);
// initialize the table info
if(o.allowTableinfo) _initTableInfo.call(this);
// create the buttons and section functions
this.toolbar();
}
function _initColumnModal() {
var o = this.options
, $e = this.$element
, $top_details = this.$top_details
, $toggle = $("<a></a>");
// localize the object
var that = this;
if(!this.$column_modal) {
this.$column_modal = $('<div></div>')
.attr("id", "dt-column-modal_" + Math.floor((Math.random()*100)+1))
.addClass("modal")
.hide();
// render the modal header
this.$column_modalheader = $("<div></div>")
.addClass("modal-header")
.append(
$("<button></button>")
.addClass("close")
.data("dismiss", "modal")
.text('x')
.click(function() {
that.$column_modal.modal('hide');
})
)
.append(
$("<h3></h3>")
.text("Toggle Columns")
);
// render the modal footer
this.$column_modalfooter = $("<div></div>")
.addClass("modal-footer")
.append(
// show the check 'all / none' columns
$('<div class="pull-left"></div>')
.append(
$('<div class="btn-group"></div>')
.append(
$('<a href="#" class="btn">Check All</a>')
.click(function() {
$(this).closest(".modal").find('a.active > i.icon-remove').each(function(){
$(this).parent().click();
})
return false;
})
, $('<a href="#" class="btn">None</a>')
.click(function() {
$(this).closest(".modal").find('a.active > i.icon-ok').each(function(){
$(this).parent().click();
})
return false;
})
)
)
, o.allowSaveColumns ? $("<a></a>")
.attr("href", "#")
.addClass("btn btn-primary")
.text("Save")
.click(function() {
_saveColumns.call(that)
return false;
}) : ""
, $("<a></a>")
.attr("href", "#")
.addClass("btn")
.text("Close")
.click(function() {
that.$column_modal.modal('hide')
return false;
})
)
// render the modal body
this.$column_modalbody = $("<div></div>")
.addClass("modal-body");
// render and add the modal to the container
this.$column_modal
.append(
this.$column_modalheader
, this.$column_modalbody
, this.$column_modalfooter
)
.appendTo(document.body);
}
// render the display modal button
$toggle
.addClass("btn")
.data("toggle", "modal")
.attr("title", "Choose which columns you would like to display.")
.attr("href", "#" + this.$column_modal.attr("id"))
.html("<i class=\"icon-cog\"></i>")
.click(function(e) {
that.$column_modal
.on('show', function () {
_updateColumnModalBody.call(that, that.$column_modalbody);
})
.modal();
return false;
});
this.buttons.unshift($toggle);
return this.$column_modal;
}
function _initFilterModal() {
var o = this.options
, $e = this.$element
, $toggle = $("<a></a>");
// render the display modal button
$toggle
.addClass("btn")
.data("toggle", "modal")
.attr("href", "#")
.attr("title", "Open the filter dialog.")
.html("<i class=\"icon-filter\"></i>")
.click(function() {
if($(o.filterModal).hasClass("modal"))
$(o.filterModal)
.modal();
else if($(o.filterModal).is(":visible"))
$(o.filterModal)
.hide();
else
$(o.filterModal)
.show();
return false;
});
this.buttons.unshift($toggle);
}
function _initPerPage() {
var o = this.options
, $e = this.$element
, that = this;
// per page options and current filter/sorting
var $perpage_select = $("<a></a>")
.addClass("btn dropdown-toggle")
.attr("title", "Change the number of rows per page.")
.attr("data-toggle", "dropdown")
.html(o.perPage + " ")
.css({ fontWeight: 'normal' })
.append(
$("<span></span>")
.addClass("caret")
);
this.buttons.push($perpage_select);
var $perpage_values = $("<ul></ul>")
.addClass("dropdown-menu")
.css({ fontSize: 'initial', fontWeight: 'normal' })
.append(
$('<li data-value="5"><a href="#">5</a></li>')
.click(function() { _updatePerPage.call(this, that); return false; })
, $('<li data-value="10"><a href="#">10</a></li>')
.click(function() { _updatePerPage.call(this, that); return false; })
, $('<li data-value="20"><a href="#">20</a></li>')
.click(function() { _updatePerPage.call(this, that); return false; })
, $('<li data-value="50"><a href="#">50</a></li>')
.click(function() { _updatePerPage.call(this, that); return false; })
, $('<li data-value="100"><a href="#">100</a></li>')
.click(function() { _updatePerPage.call(this, that); return false; })
);
this.buttons.push($perpage_values);
}
function _initTableInfo() {
var o = this.options
, $e = this.$element
, $info = $("<a></a>");
// render the display modal button
$info
.addClass("btn")
.attr("href", "#")
.html("<i class=\"icon-info-sign\"></i>")
.click(function() {
return false;
});
var $page_sort = []
, $page_filter = [];
// sort
$.each(o.sort, function(i, v){
if(!v.length) return;
var heading;
for(var column in o.columns) {
if(o.columns[column].field == v[0]) heading = o.columns[column].title;
}
$page_sort.push( heading + " " + v[1].toUpperCase() );
});
// filter
$.each(o.filter, function(k, v) {
var heading;
for(var column in o.columns) {
if(o.columns[column].field == k) heading = o.columns[column].title;
}
$page_filter.push( (heading || k) + " = '" + v + "'" );
});
$($info).popover({
placement: "bottom"
, content: $('<dl></dl>').append(
$page_sort.length > 0 ? '<dt><i class="icon-th-list"></i> Sort:</dt><dd>' + $page_sort.join(", ") + '</dd>' : ''
, $page_filter.length > 0 ? '<dt><i class="icon-filter"></i> Filter:</dt><dd>' + $page_filter.join(", ") + '</dd>' : ''
)
});
this.buttons.unshift($info);
}
function _initOverflowToggle() {
var o = this.options
, $wrapper = this.$wrapper
, $overflow = $("<a></a>");
// create the button
$overflow
.addClass("btn")
.attr("href", "#")
.attr("title", "Toggle the size of the table to fit the data or to fit the screen.")
.html("<i class=\"icon-resize-full\"></i>")
.click(function() {
if($wrapper) _toggleOverflow.call(this, $wrapper);
return false;
});
if(!this.resultset || !this.resultset.data || this.resultset.data.length == 0)
$overflow
.addClass("disabled")
this.buttons.push($overflow);
}
function _toggleOverflow(el) {
if(el.css('overflow') == 'scroll') {
$(this).children("i")
.attr("class", "icon-resize-full");
el.css({
overflow: 'visible'
, width: 'auto'
});
}
else {
$(this).children("i")
.attr("class", "icon-resize-small");
el.css({
overflow: 'scroll'
, width: el.width()
});
}
}
function _updatePerPage(that) {
var o = that.options;
// update the perpage value
o.perPage = $(this).data("value");
// the offset
var offset = o.currentPage * o.perPage;
while(offset > o.totalRows) {
o.currentPage--;
offset = o.currentPage * o.perPage;
}
if(o.currentPage < 1) o.currentPage = 1;
if($(this).popover) $(this).popover('hide');
// update the table
that.render();
return false;
}
function showError() {
var o = this.options
, $e = this.$element;
$e.empty();
// initialize the toolbar
_initToolbar.call(this);
// nearly complete... let the user apply any final adjustments
if(o.tableCallback && typeof o.tableCallback === 'function')
o.tableCallback.call(this);
this.loading( false );
if(this.$default) $e.append(this.$default);
}
function runFilter(that) {
var o = that.options;
o.filter[$(this).data("filter")] = $(this).val();
if(o.debug) console.log(o.filter);
that.render();
}
function _updateColumnModalBody(body) {
var o = this.options
, $container = $("<fieldset></fieldset>")
, that = this;
// loop through the columns
for(var column in o.columns) {
if(o.columns[column].title === "") continue;
var $item = $('<div class="control-group" style="float: left" data-column="' + column + '"><label class="control-label">' + o.columns[column].title + '</label><div class="controls"><div class="btn-group" data-toggle="buttons-radio"><a href="#" class="btn ' + (o.columns[column].hidden ? "" : "active") + '"><i class="icon-ok"></i></a><a href="#" class="btn ' + (o.columns[column].hidden ? "active" : "") + '"><i class="icon-remove"></i></a></div></div></div>')
.click(function() {
_toggleColumn.call(this, that);
return false;
});
$container.append($item);
}
body.empty();
body.append(
$("<form></form>")
.addClass("form-horizontal")
.append($container)