youjianchi
10 months ago
9 changed files with 669 additions and 91 deletions
@ -0,0 +1,322 @@ |
|||
/** |
|||
* 基于bootstrap-table-fixed-columns修改 |
|||
* 支持左右列冻结、支持固定高度 |
|||
* Copyright (c) 2019 ruoyi |
|||
*/ |
|||
(function ($) { |
|||
'use strict'; |
|||
|
|||
$.extend($.fn.bootstrapTable.defaults, { |
|||
fixedColumns: false, |
|||
fixedNumber: 1, |
|||
rightFixedColumns: false, |
|||
rightFixedNumber: 1 |
|||
}); |
|||
|
|||
var BootstrapTable = $.fn.bootstrapTable.Constructor, |
|||
_initHeader = BootstrapTable.prototype.initHeader, |
|||
_initBody = BootstrapTable.prototype.initBody, |
|||
_resetView = BootstrapTable.prototype.resetView; |
|||
|
|||
BootstrapTable.prototype.initFixedColumns = function () { |
|||
this.timeoutHeaderColumns_ = 0; |
|||
this.timeoutBodyColumns_ = 0; |
|||
if (this.options.fixedColumns) { |
|||
this.$fixedHeader = $([ |
|||
'<div class="left-fixed-table-columns">', |
|||
'<table>', |
|||
'<thead></thead>', |
|||
'</table>', |
|||
'</div>'].join('')); |
|||
|
|||
this.$fixedHeader.find('table').attr('class', this.$el.attr('class')); |
|||
this.$fixedHeaderColumns = this.$fixedHeader.find('thead'); |
|||
this.$tableHeader.before(this.$fixedHeader); |
|||
|
|||
this.$fixedBody = $([ |
|||
'<div class="left-fixed-body-columns">', |
|||
'<table>', |
|||
'<tbody></tbody>', |
|||
'</table>', |
|||
'</div>'].join('')); |
|||
|
|||
this.$fixedBody.find('table').attr('class', this.$el.attr('class')); |
|||
this.$fixedBodyColumns = this.$fixedBody.find('tbody'); |
|||
this.$tableBody.before(this.$fixedBody); |
|||
} |
|||
if (this.options.rightFixedColumns) { |
|||
this.$rightfixedBody = $([ |
|||
'<div class="right-fixed-table-columns">', |
|||
'<table>', |
|||
'<thead></thead>', |
|||
'<tbody style="background-color: #fff;"></tbody>', |
|||
'</table>', |
|||
'</div>'].join('')); |
|||
this.$rightfixedBody.find('table').attr('class', this.$el.attr('class')); |
|||
this.$rightfixedHeaderColumns = this.$rightfixedBody.find('thead'); |
|||
this.$rightfixedBodyColumns = this.$rightfixedBody.find('tbody'); |
|||
this.$tableBody.before(this.$rightfixedBody); |
|||
if (this.options.fixedColumns) { |
|||
$('.right-fixed-table-columns').attr('style','right:0px'); |
|||
} |
|||
} |
|||
}; |
|||
|
|||
BootstrapTable.prototype.initHeader = function () { |
|||
_initHeader.apply(this, Array.prototype.slice.apply(arguments)); |
|||
|
|||
if (!this.options.fixedColumns && !this.options.rightFixedColumns){ |
|||
return; |
|||
} |
|||
this.initFixedColumns(); |
|||
|
|||
var $ltr = this.$header.find('tr:eq(0)').clone(true), |
|||
$rtr = this.$header.find('tr:eq(0)').clone(), |
|||
$lths = $ltr.clone(true).find('th'), |
|||
$rths = $rtr.clone().find('th'); |
|||
|
|||
$ltr.html(''); |
|||
$rtr.html(''); |
|||
//右边列冻结
|
|||
if (this.options.rightFixedColumns) { |
|||
for (var i = 0; i < this.options.rightFixedNumber; i++) { |
|||
$rtr.append($rths.eq($rths.length - this.options.rightFixedNumber + i).clone()); |
|||
} |
|||
this.$rightfixedHeaderColumns.html('').append($rtr); |
|||
} |
|||
|
|||
//左边列冻结
|
|||
if (this.options.fixedColumns) { |
|||
for (var i = 0; i < this.options.fixedNumber; i++) { |
|||
$ltr.append($lths.eq(i).clone(true)); |
|||
} |
|||
this.$fixedHeaderColumns.html('').append($ltr); |
|||
this.$selectAll = $ltr.find('[name="btSelectAll"]'); |
|||
this.$selectAll.on('click', function () { |
|||
var checked = $(this).prop('checked'); |
|||
$(".left-fixed-body-columns input[name=btSelectItem]").filter(':enabled').prop('checked', checked); |
|||
$('.fixed-table-body input[name=btSelectItem]').closest('tr').removeClass('selected'); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
BootstrapTable.prototype.initBody = function () { |
|||
_initBody.apply(this, Array.prototype.slice.apply(arguments)); |
|||
|
|||
if (!this.options.fixedColumns && !this.options.rightFixedColumns) { |
|||
return; |
|||
} |
|||
|
|||
var that = this; |
|||
if (this.options.fixedColumns) { |
|||
this.$fixedBodyColumns.html(''); |
|||
this.$body.find('> tr[data-index]').each(function () { |
|||
var $tr = $(this).clone(true), |
|||
$tds = $tr.clone(true).find('td'); |
|||
|
|||
$tr.html(''); |
|||
for (var i = 0; i < that.options.fixedNumber; i++) { |
|||
$tr.append($tds.eq(i).clone(true)); |
|||
} |
|||
that.$fixedBodyColumns.append($tr); |
|||
}); |
|||
} |
|||
if (this.options.rightFixedColumns) { |
|||
this.$rightfixedBodyColumns.html(''); |
|||
this.$body.find('> tr[data-index]').each(function () { |
|||
var $tr = $(this).clone(), |
|||
$tds = $tr.clone().find('td'); |
|||
|
|||
$tr.html(''); |
|||
for (var i = 0; i < that.options.rightFixedNumber; i++) { |
|||
var indexTd = $tds.length - that.options.rightFixedNumber + i; |
|||
var oldTd = $tds.eq(indexTd); |
|||
var fixTd = oldTd.clone(); |
|||
var buttons = fixTd.find('button'); |
|||
//事件转移:冻结列里面的事件转移到实际按钮的事件
|
|||
buttons.each(function (key, item) { |
|||
$(item).click(function () { |
|||
that.$body.find("tr[data-index=" + $tr.attr('data-index') + "] td:eq(" + indexTd + ") button:eq(" + key + ")").click(); |
|||
}); |
|||
}); |
|||
$tr.append(fixTd); |
|||
} |
|||
that.$rightfixedBodyColumns.append($tr); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
BootstrapTable.prototype.resetView = function () { |
|||
_resetView.apply(this, Array.prototype.slice.apply(arguments)); |
|||
|
|||
if (!this.options.fixedColumns && !this.options.rightFixedColumns) { |
|||
return; |
|||
} |
|||
|
|||
clearTimeout(this.timeoutHeaderColumns_); |
|||
this.timeoutHeaderColumns_ = setTimeout($.proxy(this.fitHeaderColumns, this), this.$el.is(':hidden') ? 100 : 0); |
|||
|
|||
clearTimeout(this.timeoutBodyColumns_); |
|||
this.timeoutBodyColumns_ = setTimeout($.proxy(this.fitBodyColumns, this), this.$el.is(':hidden') ? 100 : 0); |
|||
}; |
|||
|
|||
BootstrapTable.prototype.fitHeaderColumns = function () { |
|||
var that = this, |
|||
visibleFields = this.getVisibleFields(), |
|||
headerWidth = 0; |
|||
if (that.options.fixedColumns) { |
|||
this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) { |
|||
var $this = $(this), |
|||
index = i; |
|||
|
|||
if (i >= that.options.fixedNumber) { |
|||
return false; |
|||
} |
|||
|
|||
if (that.options.detailView && !that.options.cardView) { |
|||
index = i - 1; |
|||
} |
|||
that.$fixedHeader.find('thead th[data-field="' + visibleFields[index] + '"]') |
|||
.find('.fht-cell').width($this.innerWidth()); |
|||
headerWidth += $this.outerWidth(); |
|||
}); |
|||
this.$fixedHeader.width(headerWidth + 2).show(); |
|||
} |
|||
if (that.options.rightFixedColumns) { |
|||
this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) { |
|||
var $this = $(this), |
|||
index = i; |
|||
|
|||
if (i >= visibleFields.length - that.options.rightFixedNumber) { |
|||
return false; |
|||
|
|||
|
|||
if (that.options.detailView && !that.options.cardView) { |
|||
index = i - 1; |
|||
} |
|||
that.$rightfixedBody.find('thead th[data-field="' + visibleFields[index] + '"]') |
|||
.find('.fht-cell').width($this.innerWidth() - 1); |
|||
headerWidth += $this.outerWidth(); |
|||
} |
|||
}); |
|||
this.$rightfixedBody.width(headerWidth - 1).show(); |
|||
} |
|||
}; |
|||
|
|||
BootstrapTable.prototype.fitBodyColumns = function () { |
|||
var that = this, |
|||
top = -(parseInt(this.$el.css('margin-top'))), |
|||
height = this.$tableBody.height(); |
|||
|
|||
if (that.options.fixedColumns) { |
|||
if (!this.$body.find('> tr[data-index]').length) { |
|||
this.$fixedBody.hide(); |
|||
return; |
|||
} |
|||
|
|||
if (!this.options.height) { |
|||
top = this.$fixedHeader.height()- 1; |
|||
height = height - top; |
|||
} |
|||
|
|||
this.$fixedBody.css({ |
|||
width: this.$fixedHeader.width(), |
|||
height: height, |
|||
top: top + 1 |
|||
}).show(); |
|||
|
|||
this.$body.find('> tr').each(function (i) { |
|||
that.$fixedBody.find('tr:eq(' + i + ')').height($(this).height() - 0.5); |
|||
var thattds = this; |
|||
that.$fixedBody.find('tr:eq(' + i + ')').find('td').each(function (j) { |
|||
$(this).width($($(thattds).find('td')[j]).width() + 1); |
|||
}); |
|||
}); |
|||
|
|||
$("#" + table.options.id).on("check.bs.table uncheck.bs.table", function (e, rows, $element) { |
|||
var index= $element.data('index'); |
|||
$(this).find('.bs-checkbox').find('input[data-index="' + index + '"]').prop("checked", true); |
|||
var selectFixedItem = $('.left-fixed-body-columns input[name=btSelectItem]'); |
|||
var checkAll = selectFixedItem.filter(':enabled').length && |
|||
selectFixedItem.filter(':enabled').length === |
|||
selectFixedItem.filter(':enabled').filter(':checked').length; |
|||
$(".left-fixed-table-columns input[name=btSelectAll]").prop('checked', checkAll); |
|||
$('.fixed-table-body input[name=btSelectItem]').closest('tr').removeClass('selected'); |
|||
}); |
|||
|
|||
$("#" + table.options.id).off('click', '.fixed-table-body').on('click', '.th-inner', function (event) { |
|||
$.each(that.$fixedHeader.find('th'), function (i, th) { |
|||
$(th).find('.sortable').removeClass('desc asc').addClass('both'); |
|||
}); |
|||
}); |
|||
|
|||
// events
|
|||
this.$fixedHeader.off('click', '.th-inner').on('click', '.th-inner', function (event) { |
|||
var target = $(this); |
|||
var $this = event.type === "keypress" ? $(event.currentTarget) : $(event.currentTarget).parent(), $this_ = that.$header.find('th').eq($this.index()); |
|||
|
|||
var sortOrder = ""; |
|||
if (table.options.sortName === $this.data('field')) { |
|||
sortOrder = table.options.sortOrder === 'asc' ? 'desc' : 'asc'; |
|||
} else { |
|||
sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc'; |
|||
} |
|||
table.options.sortOrder = sortOrder; |
|||
var sortName = $this.data('sortName') ? $this.data('sortName') : $this.data('field'); |
|||
if (target.parent().data().sortable) { |
|||
$.each(that.$fixedHeader.find('th'), function (i, th) { |
|||
$(th).find('.sortable').removeClass('desc asc').addClass(($(th).data('field') === sortName || $(th).data('sortName') === sortName) ? sortOrder : 'both'); |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
this.$tableBody.on('scroll', function () { |
|||
that.$fixedBody.find('table').css('top', -$(this).scrollTop()); |
|||
}); |
|||
this.$body.find('> tr[data-index]').off('hover').hover(function () { |
|||
var index = $(this).data('index'); |
|||
that.$fixedBody.find('tr[data-index="' + index + '"]').addClass('hover'); |
|||
}, function () { |
|||
var index = $(this).data('index'); |
|||
that.$fixedBody.find('tr[data-index="' + index + '"]').removeClass('hover'); |
|||
}); |
|||
this.$fixedBody.find('tr[data-index]').off('hover').hover(function () { |
|||
var index = $(this).data('index'); |
|||
that.$body.find('tr[data-index="' + index + '"]').addClass('hover'); |
|||
}, function () { |
|||
var index = $(this).data('index'); |
|||
that.$body.find('> tr[data-index="' + index + '"]').removeClass('hover'); |
|||
}); |
|||
} |
|||
if (that.options.rightFixedColumns) { |
|||
if (!this.$body.find('> tr[data-index]').length) { |
|||
this.$rightfixedBody.hide(); |
|||
return; |
|||
} |
|||
|
|||
this.$body.find('> tr').each(function (i) { |
|||
that.$rightfixedBody.find('tbody tr:eq(' + i + ')').height($(this).height()); |
|||
}); |
|||
|
|||
//// events
|
|||
this.$tableBody.on('scroll', function () { |
|||
that.$rightfixedBody.find('table').css('top', -$(this).scrollTop()); |
|||
}); |
|||
this.$body.find('> tr[data-index]').off('hover').hover(function () { |
|||
var index = $(this).data('index'); |
|||
that.$rightfixedBody.find('tr[data-index="' + index + '"]').addClass('hover'); |
|||
}, function () { |
|||
var index = $(this).data('index'); |
|||
that.$rightfixedBody.find('tr[data-index="' + index + '"]').removeClass('hover'); |
|||
}); |
|||
this.$rightfixedBody.find('tr[data-index]').off('hover').hover(function () { |
|||
var index = $(this).data('index'); |
|||
that.$body.find('tr[data-index="' + index + '"]').addClass('hover'); |
|||
}, function () { |
|||
var index = $(this).data('index'); |
|||
that.$body.find('> tr[data-index="' + index + '"]').removeClass('hover'); |
|||
}); |
|||
} |
|||
}; |
|||
|
|||
})(jQuery); |
File diff suppressed because one or more lines are too long
@ -0,0 +1,211 @@ |
|||
/** |
|||
* @author: aperez <aperez@datadec.es> |
|||
* @version: v2.0.0 |
|||
* |
|||
* @update Dennis Hernández <http://djhvscf.github.io/Blog>
|
|||
*/ |
|||
|
|||
!function($) { |
|||
'use strict'; |
|||
|
|||
var firstLoad = false; |
|||
|
|||
var sprintf = $.fn.bootstrapTable.utils.sprintf; |
|||
|
|||
var showAvdSearch = function(pColumns, searchTitle, searchText, that) { |
|||
if (!$("#avdSearchModal" + "_" + that.options.idTable).hasClass("modal")) { |
|||
var vModal = sprintf("<div id=\"avdSearchModal%s\" class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"mySmallModalLabel\" aria-hidden=\"true\">", "_" + that.options.idTable); |
|||
vModal += "<div class=\"modal-dialog modal-xs\">"; |
|||
vModal += " <div class=\"modal-content\">"; |
|||
vModal += " <div class=\"modal-header\">"; |
|||
vModal += " <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\" >×</button>"; |
|||
vModal += sprintf(" <h4 class=\"modal-title\">%s</h4>", searchTitle); |
|||
vModal += " </div>"; |
|||
vModal += " <div class=\"modal-body modal-body-custom\">"; |
|||
vModal += sprintf(" <div class=\"container-fluid\" id=\"avdSearchModalContent%s\" style=\"padding-right: 0px;padding-left: 0px;\" >", "_" + that.options.idTable); |
|||
vModal += " </div>"; |
|||
vModal += " </div>"; |
|||
vModal += " </div>"; |
|||
vModal += " </div>"; |
|||
vModal += "</div>"; |
|||
|
|||
$("body").append($(vModal)); |
|||
|
|||
var vFormAvd = createFormAvd(pColumns, searchText, that), |
|||
timeoutId = 0;; |
|||
|
|||
$('#avdSearchModalContent' + "_" + that.options.idTable).append(vFormAvd.join('')); |
|||
|
|||
$('#' + that.options.idForm).off('keyup blur', 'input').on('keyup blur', 'input', function (event) { |
|||
clearTimeout(timeoutId); |
|||
timeoutId = setTimeout(function () { |
|||
that.onColumnAdvancedSearch(event); |
|||
}, that.options.searchTimeOut); |
|||
}); |
|||
|
|||
$("#btnCloseAvd" + "_" + that.options.idTable).click(function() { |
|||
$("#avdSearchModal" + "_" + that.options.idTable).modal('hide'); |
|||
}); |
|||
|
|||
$("#avdSearchModal" + "_" + that.options.idTable).modal(); |
|||
} else { |
|||
$("#avdSearchModal" + "_" + that.options.idTable).modal(); |
|||
} |
|||
}; |
|||
|
|||
var createFormAvd = function(pColumns, searchText, that) { |
|||
var htmlForm = []; |
|||
htmlForm.push(sprintf('<form class="form-horizontal" id="%s" action="%s" >', that.options.idForm, that.options.actionForm)); |
|||
for (var i in pColumns) { |
|||
var vObjCol = pColumns[i]; |
|||
if (!vObjCol.checkbox && vObjCol.visible && vObjCol.searchable) { |
|||
htmlForm.push('<div class="form-group">'); |
|||
htmlForm.push(sprintf('<label class="col-sm-4 control-label">%s</label>', vObjCol.title)); |
|||
htmlForm.push('<div class="col-sm-6">'); |
|||
htmlForm.push(sprintf('<input type="text" class="form-control input-md" name="%s" placeholder="%s" id="%s">', vObjCol.field, vObjCol.title, vObjCol.field)); |
|||
htmlForm.push('</div>'); |
|||
htmlForm.push('</div>'); |
|||
} |
|||
} |
|||
|
|||
htmlForm.push('<div class="form-group">'); |
|||
htmlForm.push('<div class="col-sm-offset-9 col-sm-3">'); |
|||
htmlForm.push(sprintf('<button type="button" id="btnCloseAvd%s" class="btn btn-default" >%s</button>', "_" + that.options.idTable, searchText)); |
|||
htmlForm.push('</div>'); |
|||
htmlForm.push('</div>'); |
|||
htmlForm.push('</form>'); |
|||
|
|||
return htmlForm; |
|||
}; |
|||
|
|||
$.extend($.fn.bootstrapTable.defaults, { |
|||
advancedSearch: false, |
|||
idForm: 'advancedSearch', |
|||
actionForm: '', |
|||
idTable: undefined, |
|||
onColumnAdvancedSearch: function (field, text) { |
|||
return false; |
|||
} |
|||
}); |
|||
|
|||
$.extend($.fn.bootstrapTable.defaults.icons, { |
|||
advancedSearchIcon: 'glyphicon-chevron-down' |
|||
}); |
|||
|
|||
$.extend($.fn.bootstrapTable.Constructor.EVENTS, { |
|||
'column-advanced-search.bs.table': 'onColumnAdvancedSearch' |
|||
}); |
|||
|
|||
$.extend($.fn.bootstrapTable.locales, { |
|||
formatAdvancedSearch: function() { |
|||
return 'Advanced search'; |
|||
}, |
|||
formatAdvancedCloseButton: function() { |
|||
return "Close"; |
|||
} |
|||
}); |
|||
|
|||
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales); |
|||
|
|||
var BootstrapTable = $.fn.bootstrapTable.Constructor, |
|||
_initToolbar = BootstrapTable.prototype.initToolbar, |
|||
_load = BootstrapTable.prototype.load, |
|||
_initSearch = BootstrapTable.prototype.initSearch; |
|||
|
|||
BootstrapTable.prototype.initToolbar = function() { |
|||
_initToolbar.apply(this, Array.prototype.slice.apply(arguments)); |
|||
|
|||
if (!this.options.search) { |
|||
return; |
|||
} |
|||
|
|||
if (!this.options.advancedSearch) { |
|||
return; |
|||
} |
|||
|
|||
if (!this.options.idTable) { |
|||
return; |
|||
} |
|||
|
|||
var that = this, |
|||
html = []; |
|||
|
|||
html.push(sprintf('<div class="columns columns-%s btn-group pull-%s" role="group">', this.options.buttonsAlign, this.options.buttonsAlign)); |
|||
html.push(sprintf('<button class="btn btn-default%s' + '" type="button" name="advancedSearch" title="%s">', that.options.iconSize === undefined ? '' : ' btn-' + that.options.iconSize, that.options.formatAdvancedSearch())); |
|||
html.push(sprintf('<i class="%s %s"></i>', that.options.iconsPrefix, that.options.icons.advancedSearchIcon)) |
|||
html.push('</button></div>'); |
|||
|
|||
that.$toolbar.prepend(html.join('')); |
|||
|
|||
that.$toolbar.find('button[name="advancedSearch"]') |
|||
.off('click').on('click', function() { |
|||
showAvdSearch(that.columns, that.options.formatAdvancedSearch(), that.options.formatAdvancedCloseButton(), that); |
|||
}); |
|||
}; |
|||
|
|||
BootstrapTable.prototype.load = function(data) { |
|||
_load.apply(this, Array.prototype.slice.apply(arguments)); |
|||
|
|||
if (!this.options.advancedSearch) { |
|||
return; |
|||
} |
|||
|
|||
if (typeof this.options.idTable === 'undefined') { |
|||
return; |
|||
} else { |
|||
if (!firstLoad) { |
|||
var height = parseInt($(".bootstrap-table").height()); |
|||
height += 10; |
|||
$("#" + this.options.idTable).bootstrapTable("resetView", {height: height}); |
|||
firstLoad = true; |
|||
} |
|||
} |
|||
}; |
|||
|
|||
BootstrapTable.prototype.initSearch = function () { |
|||
_initSearch.apply(this, Array.prototype.slice.apply(arguments)); |
|||
|
|||
if (!this.options.advancedSearch) { |
|||
return; |
|||
} |
|||
|
|||
var that = this; |
|||
var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial; |
|||
|
|||
this.data = fp ? $.grep(this.data, function (item, i) { |
|||
for (var key in fp) { |
|||
var fval = fp[key].toLowerCase(); |
|||
var value = item[key]; |
|||
value = $.fn.bootstrapTable.utils.calculateObjectValue(that.header, |
|||
that.header.formatters[$.inArray(key, that.header.fields)], |
|||
[value, item, i], value); |
|||
|
|||
if (!($.inArray(key, that.header.fields) !== -1 && |
|||
(typeof value === 'string' || typeof value === 'number') && |
|||
(value + '').toLowerCase().indexOf(fval) !== -1)) { |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
}) : this.data; |
|||
}; |
|||
|
|||
BootstrapTable.prototype.onColumnAdvancedSearch = function (event) { |
|||
var text = $.trim($(event.currentTarget).val()); |
|||
var $field = $(event.currentTarget)[0].id; |
|||
|
|||
if ($.isEmptyObject(this.filterColumnsPartial)) { |
|||
this.filterColumnsPartial = {}; |
|||
} |
|||
if (text) { |
|||
this.filterColumnsPartial[$field] = text; |
|||
} else { |
|||
delete this.filterColumnsPartial[$field]; |
|||
} |
|||
|
|||
this.options.pageNumber = 1; |
|||
this.onSearch(event); |
|||
this.updatePagination(); |
|||
this.trigger('column-advanced-search', $field, text); |
|||
}; |
|||
}(jQuery); |
@ -0,0 +1,7 @@ |
|||
/* |
|||
* bootstrap-table - v1.11.0 - 2016-07-02 |
|||
* https://github.com/wenzhixin/bootstrap-table
|
|||
* Copyright (c) 2016 zhixin wen |
|||
* Licensed MIT License |
|||
*/ |
|||
!function(a){"use strict";var b=!1,c=a.fn.bootstrapTable.utils.sprintf,d=function(b,d,f,g){if(a("#avdSearchModal_"+g.options.idTable).hasClass("modal"))a("#avdSearchModal_"+g.options.idTable).modal();else{var h=c('<div id="avdSearchModal%s" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">',"_"+g.options.idTable);h+='<div class="modal-dialog modal-xs">',h+=' <div class="modal-content">',h+=' <div class="modal-header">',h+=' <button type="button" class="close" data-dismiss="modal" aria-hidden="true" >×</button>',h+=c(' <h4 class="modal-title">%s</h4>',d),h+=" </div>",h+=' <div class="modal-body modal-body-custom">',h+=c(' <div class="container-fluid" id="avdSearchModalContent%s" style="padding-right: 0px;padding-left: 0px;" >',"_"+g.options.idTable),h+=" </div>",h+=" </div>",h+=" </div>",h+=" </div>",h+="</div>",a("body").append(a(h));var i=e(b,f,g),j=0;a("#avdSearchModalContent_"+g.options.idTable).append(i.join("")),a("#"+g.options.idForm).off("keyup blur","input").on("keyup blur","input",function(a){clearTimeout(j),j=setTimeout(function(){g.onColumnAdvancedSearch(a)},g.options.searchTimeOut)}),a("#btnCloseAvd_"+g.options.idTable).click(function(){a("#avdSearchModal_"+g.options.idTable).modal("hide")}),a("#avdSearchModal_"+g.options.idTable).modal()}},e=function(a,b,d){var e=[];e.push(c('<form class="form-horizontal" id="%s" action="%s" >',d.options.idForm,d.options.actionForm));for(var f in a){var g=a[f];!g.checkbox&&g.visible&&g.searchable&&(e.push('<div class="form-group">'),e.push(c('<label class="col-sm-4 control-label">%s</label>',g.title)),e.push('<div class="col-sm-6">'),e.push(c('<input type="text" class="form-control input-md" name="%s" placeholder="%s" id="%s">',g.field,g.title,g.field)),e.push("</div>"),e.push("</div>"))}return e.push('<div class="form-group">'),e.push('<div class="col-sm-offset-9 col-sm-3">'),e.push(c('<button type="button" id="btnCloseAvd%s" class="btn btn-default" >%s</button>',"_"+d.options.idTable,b)),e.push("</div>"),e.push("</div>"),e.push("</form>"),e};a.extend(a.fn.bootstrapTable.defaults,{advancedSearch:!1,idForm:"advancedSearch",actionForm:"",idTable:void 0,onColumnAdvancedSearch:function(){return!1}}),a.extend(a.fn.bootstrapTable.defaults.icons,{advancedSearchIcon:"glyphicon-chevron-down"}),a.extend(a.fn.bootstrapTable.Constructor.EVENTS,{"column-advanced-search.bs.table":"onColumnAdvancedSearch"}),a.extend(a.fn.bootstrapTable.locales,{formatAdvancedSearch:function(){return"Advanced search"},formatAdvancedCloseButton:function(){return"Close"}}),a.extend(a.fn.bootstrapTable.defaults,a.fn.bootstrapTable.locales);var f=a.fn.bootstrapTable.Constructor,g=f.prototype.initToolbar,h=f.prototype.load,i=f.prototype.initSearch;f.prototype.initToolbar=function(){if(g.apply(this,Array.prototype.slice.apply(arguments)),this.options.search&&this.options.advancedSearch&&this.options.idTable){var a=this,b=[];b.push(c('<div class="columns columns-%s btn-group pull-%s" role="group">',this.options.buttonsAlign,this.options.buttonsAlign)),b.push(c('<button class="btn btn-default%s" type="button" name="advancedSearch" title="%s">',void 0===a.options.iconSize?"":" btn-"+a.options.iconSize,a.options.formatAdvancedSearch())),b.push(c('<i class="%s %s"></i>',a.options.iconsPrefix,a.options.icons.advancedSearchIcon)),b.push("</button></div>"),a.$toolbar.prepend(b.join("")),a.$toolbar.find('button[name="advancedSearch"]').off("click").on("click",function(){d(a.columns,a.options.formatAdvancedSearch(),a.options.formatAdvancedCloseButton(),a)})}},f.prototype.load=function(){if(h.apply(this,Array.prototype.slice.apply(arguments)),this.options.advancedSearch&&"undefined"!=typeof this.options.idTable&&!b){var c=parseInt(a(".bootstrap-table").height());c+=10,a("#"+this.options.idTable).bootstrapTable("resetView",{height:c}),b=!0}},f.prototype.initSearch=function(){if(i.apply(this,Array.prototype.slice.apply(arguments)),this.options.advancedSearch){var b=this,c=a.isEmptyObject(this.filterColumnsPartial)?null:this.filterColumnsPartial;this.data=c?a.grep(this.data,function(d,e){for(var f in c){var g=c[f].toLowerCase(),h=d[f];if(h=a.fn.bootstrapTable.utils.calculateObjectValue(b.header,b.header.formatters[a.inArray(f,b.header.fields)],[h,d,e],h),-1===a.inArray(f,b.header.fields)||"string"!=typeof h&&"number"!=typeof h||-1===(h+"").toLowerCase().indexOf(g))return!1}return!0}):this.data}},f.prototype.onColumnAdvancedSearch=function(b){var c=a.trim(a(b.currentTarget).val()),d=a(b.currentTarget)[0].id;a.isEmptyObject(this.filterColumnsPartial)&&(this.filterColumnsPartial={}),c?this.filterColumnsPartial[d]=c:delete this.filterColumnsPartial[d],this.options.pageNumber=1,this.onSearch(b),this.updatePagination(),this.trigger("column-advanced-search",d,c)}}(jQuery); |
Loading…
Reference in new issue