43
44
this.$default = this.$element.children().length ?
44
45
this.$element.children() :
46
.addClass("alert alert-error")
47
// ------------- Start ntop Patch ---------------
48
.addClass("alert alert-danger")
49
// ------------- End ntop Patch ---------------
47
50
.html("No Results Found");
49
52
this.$element.addClass("clearfix");
53
56
localStorage[this.localStorageId] = 'false';
59
if(this.options.tablePreRender && typeof this.options.tablePreRender === 'function')
60
this.options.tablePreRender.call(this)
62
// initialize the toolbar
63
_initToolbar.call(this)
56
65
if(this.options.autoLoad === true) this.render();
93
102
// pull in the data from the ajax call
103
if (o.debug) console.log($.extend({}, o.post, {
104
currentPage: o.currentPage
94
109
if(o.url !== "") {
112
// ------------- Start ntop Patch ---------------
98
114
, dataType: "json"
99
, data: $.extend({}, o.get, {
115
, data: $.extend({}, o.post, {
100
116
currentPage: o.currentPage
101
117
, perPage: o.perPage
102
, sortColumn: o.sort[0][0]
103
, sortOrder: o.sort[0][1]
118
, sortColumn: (o.sort.length > 0) ? o.sort[0][0] : null
119
, sortOrder: (o.sort.length > 0) ? o.sort[0][1] : null
120
// ------------- End ntop Patch -----------------
104
121
, filter: o.filter
106
123
, success: function( res ) {
107
if(o.debug) console.log(res);
109
if(!res || res === undefined) {
110
showError.call(that);
114
124
that.resultset = res;
116
if(!res.data || res.data.length === 0) {
126
if(!res || res === undefined || !res.data || res.data.length == 0) {
117
127
showError.call(that);
129
139
// set the current page if we're forcing it from the server
130
140
if(res.currentPage) o.currentPage = parseInt(res.currentPage);
132
if(o.tablePreRender && typeof o.tablePreRender === 'function')
133
o.tablePreRender.call(that);
135
// TODO FUTURE FEATURE: retrieve the saved columns
136
//_retrieveColumns.call(that, that.localStorageId);
142
// retrieve the saved columns
143
_retrieveColumns.call(that, localStorage[that.localStorageId])
138
145
// append the table
139
146
$e.append(that.table());
193
.addClass("progress progress-striped active")
194
.append($('<div class="bar" style="width: 100%"></div>'))
200
// ------------- Start ntop Patch ---------------
201
.addClass("progress progress-striped")
204
.addClass("progress-bar progress-bar-info")
205
.attr('style', "width: 40%")
206
// ------------- End ntop Patch -----------------
196
.appendTo($e.parent());
209
.appendTo(document.body)
241
254
$e.before(this.$section_header);
244
if(!this.$section_header) {
245
this.$section_header = $("<div></div>");
247
this.$section_header.append(this.$toolbar);
257
if(!this.$toolbar_container) {
258
this.$toolbar_container = $("<div></div>")
259
.addClass('dt-toolbar-container clearfix')
262
this.$toolbar_container
263
.append(this.$toolbar)
250
267
return this.$toolbar;
330
351
, footer: function () {
331
var res = this.resultset;
353
, res = this.resultset
333
355
if(!this.$footer) {
334
356
this.$footer = $('<tfoot></tfoot>');
358
// loop through the columns
359
for(column in o.columns) {
360
var $cell = $('<td></td>')
363
.data("cell_properties", o.columns[column])
364
.addClass(o.columns[column].classname)
366
this.$footer.append($cell);
336
369
// any final user adjustments to the footer
337
370
if(o.footerCallback && typeof o.footerCallback === 'function')
338
o.footerCallback.call(this);
371
o.footerCallback.call(this, this.resultset.footer)
341
374
.append(this.$footer);
423
456
// preprocess on the cell data for a column
424
457
if(o.columns[column].callback && typeof o.columns[column].callback === "function")
425
celldata = o.columns[column].callback( data, o.columns[column] );
458
celldata = o.columns[column].callback.call( $cell, data, o.columns[column] )
428
461
.data("cell_properties", o.columns[column])
429
462
.addClass(o.columns[column].classname)
430
.html(celldata || " ");
463
.append(celldata || " ")
432
465
if(o.columns[column].css) $cell.css(o.columns[column].css);
461
494
, o = e.data.options
464
colprop.sortOrder = colprop.sortOrder ? (colprop.sortOrder == "desc" ? "asc" : "") : "desc";
497
colprop.sortOrder = colprop.sortOrder ? (colprop.sortOrder == "asc" ? "desc" : "") : "asc";
466
499
if(o.allowMultipleSort) {
467
500
// does the sort already exist?
494
527
if(o.perPage >= res.totalRows) return;
496
529
if(!this.$pagination) {
497
this.$pagination = $("<div></div>")
498
.addClass("pagination pagination-right");
530
this.$pagination = $("<div></div>").addClass("pull-right");
500
532
// how many pages?
501
533
o.pageCount = Math.ceil(res.totalRows / o.perPage);
503
535
// setup the pager container and the quick page buttons
504
var $pager = $("<ul></ul>")
536
var $pager = $("<ul></ul>").addClass("pagination")
505
537
, $first = $("<li></li>").append(
507
539
.attr("href", "#")
509
.html("← First")
510
542
.click(function() {
511
if (o.currentPage > 1) {
546
574
.attr("href", "#")
547
575
.data("page", o.pageCount)
549
577
.click(function() {
550
if (o.currentPage < o.pageCount) {
551
o.currentPage = o.pageCount;
578
o.currentPage = o.pageCount
654
687
if(!this.$column_modal) {
688
var randId = Math.floor((Math.random()*100)+1);
655
689
this.$column_modal = $('<div></div>')
656
.attr("id", "dt-column-modal_" + Math.floor((Math.random()*100)+1))
690
.attr("id", "dt-column-modal_" + randId)
691
.attr("tabindex","-1")
692
.attr("role","dialog")
693
.attr("aria-labelledby", "dt-column-modal-label_" + randId)
694
.attr("aria-hidden","true")
695
.addClass("modal fade")
660
698
// render the modal header
664
702
$("<button></button>")
665
703
.addClass("close")
666
704
.data("dismiss", "modal")
705
.attr("aria-hidden","true")
669
708
that.$column_modal.modal('hide');
713
.addClass("modal-title")
714
.attr("id","dt-column-modal-label_" + randId)
674
715
.text("Toggle Columns")
678
719
this.$column_modalfooter = $("<div></div>")
679
720
.addClass("modal-footer")
683
.addClass("btn btn-primary")
722
// show the check 'all / none' columns
723
$('<div class="pull-left"></div>')
725
$('<div class="btn-group"></div>')
727
$('<button></button>')
728
.addClass("btn btn-info")
731
.addClass("glyphicon glyphicon-check")
735
$(this).closest(".modal").find('button.on-off').each(function () {
736
if($(this).data('column-hidden')){
742
$('<button></button>')
743
.addClass("btn btn-warning")
746
.addClass("glyphicon glyphicon-unchecked")
750
$(this).closest(".modal").find('button.on-off').each(function () {
751
if(!$(this).data('column-hidden')){
760
, o.allowSaveColumns ? $("<button></button>")
761
.addClass("btn btn-primary")
764
_saveColumns.call(that)
768
, $("<button></button>")
769
.addClass("btn btn-default")
770
.data('dismiss', 'modal')
685
775
.click(function() {
686
_saveColumns.call(that);
776
that.$column_modal.modal('hide')
692
782
this.$column_modalbody = $("<div></div>")
693
783
.addClass("modal-body");
785
this.$column_modaldialog = $("<div></div>")
786
.addClass("modal-dialog")
789
.addClass("modal-content")
791
this.$column_modalheader
792
,this.$column_modalbody
793
,this.$column_modalfooter
695
797
// render and add the modal to the container
696
798
this.$column_modal
698
this.$column_modalheader
699
, this.$column_modalbody
700
, this.$column_modalfooter
702
.appendTo(document.body);
800
this.$column_modaldialog
801
).appendTo(document.body);
705
803
// render the display modal button
708
806
.data("toggle", "modal")
807
.data("content", "Choose which columns you would like to display.")
808
.data("target","#" + this.$column_modal.attr("id"))
709
809
.attr("href", "#" + this.$column_modal.attr("id"))
710
.html("<i class=\"icon-cog\"></i>")
812
.addClass("glyphicon glyphicon-cog")
711
814
.click(function(e) {
712
815
that.$column_modal
713
.on('show', function () {
816
.on('show.bs.modal', function () {
817
if(o.debug) console.log(that);
714
818
_updateColumnModalBody.call(that, that.$column_modalbody);
719
827
this.buttons.unshift($toggle);
829
if(o.debug) console.log($toggle);
721
831
return this.$column_modal;
726
836
, $e = this.$element
727
837
, $toggle = $("<a></a>");
729
o.filterModal.hide();
731
839
// render the display modal button
734
842
.data("toggle", "modal")
735
843
.attr("href", "#")
736
.html("<i class=\"icon-filter\"></i>")
844
.data("content", "Open the filter dialog.")
847
.addClass("glyphicon glyphicon-filter")
737
849
.click(function() {
850
if($(o.filterModal).hasClass("modal"))
853
else if($(o.filterModal).is(":visible"))
742
866
this.buttons.unshift($toggle);
750
874
// per page options and current filter/sorting
751
875
var $perpage_select = $("<a></a>")
752
876
.addClass("btn dropdown-toggle")
877
.data("content", "Change the number of rows per page.")
753
878
.attr("data-toggle", "dropdown")
754
879
.html(o.perPage + " ")
755
880
.css({ fontWeight: 'normal' })
757
882
$("<span></span>")
758
883
.addClass("caret")
760
889
this.buttons.push($perpage_select);
762
891
var $perpage_values = $("<ul></ul>")
763
892
.addClass("dropdown-menu")
764
893
.css({ fontSize: 'initial', fontWeight: 'normal' })
766
$('<li data-value="5"><a href="#">5</a></li>')
767
.click(function() { _updatePerPage.call(this, that); return false; })
768
, $('<li data-value="10"><a href="#">10</a></li>')
895
$('<li data-value="10"><a href="#">10</a></li>')
769
896
.click(function() { _updatePerPage.call(this, that); return false; })
770
897
, $('<li data-value="20"><a href="#">20</a></li>')
771
898
.click(function() { _updatePerPage.call(this, that); return false; })
773
900
.click(function() { _updatePerPage.call(this, that); return false; })
774
901
, $('<li data-value="100"><a href="#">100</a></li>')
775
902
.click(function() { _updatePerPage.call(this, that); return false; })
903
, $('<li data-value="150"><a href="#">200</a></li>')
904
.click(function() { _updatePerPage.call(this, that); return false; })
777
906
this.buttons.push($perpage_values);
813
945
$page_filter.push( (heading || k) + " = '" + v + "'" );
949
$('<dl></dl>').append(
950
$page_sort.length > 0 ? '<dt><i class="icon-th-list"></i> Sort:</dt><dd>' + $page_sort.join(", ") + '</dd>' : ''
952
$page_filter.length > 0 ? '<dt><i class="icon-filter"></i> Filter:</dt><dd>' + $page_filter.join(", ") + '</dd>' : ''
817
955
placement: "bottom"
818
, content: $('<dl></dl>').append(
819
$page_sort.length > 0 ? '<dt><i class="icon-th-list"></i> Sort:</dt><dd>' + $page_sort.join(", ") + '</dd>' : ''
820
, $page_filter.length > 0 ? '<dt><i class="icon-filter"></i> Filter:</dt><dd>' + $page_filter.join(", ") + '</dd>' : ''
824
958
this.buttons.unshift($info);
832
966
// create the button
834
.addClass("btn add-on")
835
969
.attr("href", "#")
836
.html("<i class=\"icon-resize-full\"></i>")
970
.attr("title", "Toggle the size of the table to fit the data or to fit the screen.")
973
.addClass("glyphicon glyphicon-resize-full")
837
975
.click(function() {
838
_toggleOverflow.call(this, $wrapper);
976
if($wrapper) _toggleOverflow.call(this, $wrapper);
980
if(!this.resultset || !this.resultset.data || this.resultset.data.length == 0)
982
.addClass("disabled")
841
984
this.buttons.push($overflow);
844
987
function _toggleOverflow(el) {
845
988
if(el.css('overflow') == 'scroll') {
846
$(this).children("i")
847
.attr("class", "icon-resize-full");
989
$(this).children("span.glyphicon")
990
.attr("class", "glyphicon glyphicon-resize-full");
850
993
overflow: 'visible'
914
1057
function _updateColumnModalBody(body) {
915
1058
var o = this.options
916
, $container = $("<fieldset></fieldset>")
1059
, $container = $("<form></form>").addClass("form-inline")
919
1062
// loop through the columns
920
1063
for(var column in o.columns) {
921
1064
if(o.columns[column].title === "") continue;
922
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>')
924
_toggleColumn.call(this, that);
1065
var $item = $('<div></div></br>')
1066
.addClass('form-group')
1068
$("<label></label>")
1069
.addClass("control-label")
1071
o.columns[column].title,
1073
$("<button></button>")
1074
.addClass("on-off btn " + (o.columns[column].hidden ? 'btn-info' : 'btn-warning'))
1075
.data("column", column)
1076
.data("column-hidden",o.columns[column].hidden)
1077
.text(o.columns[column].hidden ? "ON" : "OFF")
1078
.click(function () {
1079
_toggleColumn.call(this, that);
928
1084
$container.append($item);
934
.addClass("form-horizontal")
944
1098
if($column.is(":visible")) {
946
1100
o.columns[column].hidden = true;
1101
$(this).removeClass("btn-warning").addClass("btn-info").text("ON").data("column-hidden",true);
950
1105
o.columns[column].hidden = false;
1106
$(this).removeClass("btn-info").addClass("btn-warning").text("OFF").data("column-hidden",false);
955
.removeClass("active");
957
o.columns[column].hidden ?
958
$(this).find(".icon-remove").parent().addClass("active") :
959
$(this).find(".icon-ok").parent().addClass("active");
993
1140
, columns = data ? JSON.parse(data) : []
994
1141
, res = this.resultset;
996
for(var column in o.columns) {
997
o.columns[column] = $.extend({}, o.columns[column], (res.columns ? res.columns[column] : []), columns[column]);
1143
// if the server doesn't pass the column property back
1144
if(!res.columns) res.columns = [];
1146
for(column in o.columns) {
1147
o.columns[column] = $.extend({}, o.columns[column], res.columns[column], columns[column]);
1049
1199
$.fn.datatable.defaults = {
1052
, title: 'Data Table Results'
1053
, class: 'table table-striped table-bordered'
1060
, sectionHeader: undefined
1063
, showPagination: false
1064
, showTopPagination: false
1067
, showFilterRow: false
1068
, filterModal: undefined
1069
, allowExport: false
1070
, allowOverflow: true
1071
, allowMultipleSort: false
1072
, toggleColumns: true
1075
, ascending: '<i class="icon-chevron-up"></i>'
1076
, descending: '<i class="icon-chevron-down"></i>'
1077
, rowCallback: undefined
1078
, tableCallback: undefined
1079
, headerCallback: undefined
1080
, footerCallback: undefined
1081
, tablePreRender: undefined
1202
title: 'Data Table Results',
1203
class: 'table table-striped table-bordered',
1210
sectionHeader: undefined,
1213
showPagination: true,
1214
showTopPagination: false,
1217
showFilterRow: false,
1218
filterModal: undefined,
1220
allowOverflow: true,
1221
allowMultipleSort: false,
1222
allowSaveColumns: true,
1223
toggleColumns: true,
1226
ascending: $("<span></span>").addClass("glyphicon glyphicon-chevron-up"),
1227
descending: $("<span></span>").addClass("glyphicon glyphicon-chevron-down"),
1228
rowCallback: undefined,
1229
tableCallback: undefined,
1230
headerCallback: undefined,
1231
footerCallback: undefined,
1232
tablePreRender: undefined,
1086
1235
})(window.jQuery);