mirror of https://gitee.com/karson/fastadmin.git
!398 解决在使用Table组件时,传递pageSize参数确被设置全局的问题,并开放全局页面显示数方法
Merge pull request !398 from Henry/page-sizepull/397/MERGE
commit
be2f342044
|
|
@ -68,13 +68,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//当表格分页变更时
|
|
||||||
table.on('page-change.bs.table', function (e, page, pagesize) {
|
|
||||||
if (!isNaN(pagesize)) {
|
|
||||||
localStorage.setItem("pagesize-addon", pagesize);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Template.helper("Moment", Moment);
|
Template.helper("Moment", Moment);
|
||||||
Template.helper("addons", Config['addons']);
|
Template.helper("addons", Config['addons']);
|
||||||
|
|
||||||
|
|
@ -90,6 +83,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
||||||
// 初始化表格
|
// 初始化表格
|
||||||
table.bootstrapTable({
|
table.bootstrapTable({
|
||||||
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
url: $.fn.bootstrapTable.defaults.extend.index_url,
|
||||||
|
pageSize: 50,
|
||||||
queryParams: function (params) {
|
queryParams: function (params) {
|
||||||
var userinfo = Controller.api.userinfo.get();
|
var userinfo = Controller.api.userinfo.get();
|
||||||
$.extend(params, {
|
$.extend(params, {
|
||||||
|
|
@ -181,7 +175,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
|
||||||
commonSearch: true,
|
commonSearch: true,
|
||||||
searchFormVisible: true,
|
searchFormVisible: true,
|
||||||
searchFormTemplate: 'searchformtpl',
|
searchFormTemplate: 'searchformtpl',
|
||||||
pageSize: localStorage.getItem('pagesize-addon') || 50,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 为表格绑定事件
|
// 为表格绑定事件
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -11601,7 +11601,7 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
|
||||||
},
|
},
|
||||||
ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列
|
ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列
|
||||||
},
|
},
|
||||||
pageSize: localStorage.getItem("pagesize") || 10,
|
pageSize: localStorage.getItem('page-size') || 10,
|
||||||
pageList: [10, 15, 20, 25, 50, 'All'],
|
pageList: [10, 15, 20, 25, 50, 'All'],
|
||||||
pagination: true,
|
pagination: true,
|
||||||
clickToSelect: true, //是否启用点击选中
|
clickToSelect: true, //是否启用点击选中
|
||||||
|
|
@ -11765,12 +11765,6 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
|
||||||
table.on('refresh.bs.table', function (e, settings, data) {
|
table.on('refresh.bs.table', function (e, settings, data) {
|
||||||
$(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin");
|
$(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin");
|
||||||
});
|
});
|
||||||
//当表格分页变更时
|
|
||||||
table.on('page-change.bs.table', function (e, page, pagesize) {
|
|
||||||
if (!isNaN(pagesize)) {
|
|
||||||
localStorage.setItem("pagesize", pagesize);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//当执行搜索时
|
//当执行搜索时
|
||||||
table.on('search.bs.table common-search.bs.table', function (e, settings, data) {
|
table.on('search.bs.table common-search.bs.table', function (e, settings, data) {
|
||||||
table.trigger("uncheckbox");
|
table.trigger("uncheckbox");
|
||||||
|
|
@ -12115,6 +12109,12 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
|
||||||
Table.list[id] = table;
|
Table.list[id] = table;
|
||||||
return table;
|
return table;
|
||||||
},
|
},
|
||||||
|
// 设置全局分页的单页显示数
|
||||||
|
pageSize: function (pageSize) {
|
||||||
|
if (!isNaN(pageSize)) {
|
||||||
|
localStorage.setItem('page-size', pageSize);
|
||||||
|
}
|
||||||
|
},
|
||||||
// 批量操作请求
|
// 批量操作请求
|
||||||
multi: function (action, ids, table, element) {
|
multi: function (action, ids, table, element) {
|
||||||
var options = table.bootstrapTable('getOptions');
|
var options = table.bootstrapTable('getOptions');
|
||||||
|
|
@ -12557,387 +12557,387 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
|
||||||
return Table;
|
return Table;
|
||||||
});
|
});
|
||||||
|
|
||||||
// jQuery List DragSort v0.5.2
|
// jQuery List DragSort v0.5.2
|
||||||
// Website: http://dragsort.codeplex.com/
|
// Website: http://dragsort.codeplex.com/
|
||||||
// License: http://dragsort.codeplex.com/license
|
// License: http://dragsort.codeplex.com/license
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
|
|
||||||
$.fn.dragsort = function(options) {
|
$.fn.dragsort = function(options) {
|
||||||
if (options == "destroy") {
|
if (options == "destroy") {
|
||||||
$(this.selector).trigger("dragsort-uninit");
|
$(this.selector).trigger("dragsort-uninit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts = $.extend({}, $.fn.dragsort.defaults, options);
|
var opts = $.extend({}, $.fn.dragsort.defaults, options);
|
||||||
var lists = [];
|
var lists = [];
|
||||||
var list = null, lastPos = null;
|
var list = null, lastPos = null;
|
||||||
|
|
||||||
this.each(function(i, cont) {
|
this.each(function(i, cont) {
|
||||||
|
|
||||||
//if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected
|
//if list container is table, the browser automatically wraps rows in tbody if not specified so change list container to tbody so that children returns rows as user expected
|
||||||
if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody"))
|
if ($(cont).is("table") && $(cont).children().size() == 1 && $(cont).children().is("tbody"))
|
||||||
cont = $(cont).children().get(0);
|
cont = $(cont).children().get(0);
|
||||||
|
|
||||||
var newList = {
|
var newList = {
|
||||||
draggedItem: null,
|
draggedItem: null,
|
||||||
placeHolderItem: null,
|
placeHolderItem: null,
|
||||||
pos: null,
|
pos: null,
|
||||||
offset: null,
|
offset: null,
|
||||||
offsetLimit: null,
|
offsetLimit: null,
|
||||||
scroll: null,
|
scroll: null,
|
||||||
container: cont,
|
container: cont,
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
//set options to default values if not set
|
//set options to default values if not set
|
||||||
opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName;
|
opts.tagName = opts.tagName == "" ? ($(this.container).children().size() == 0 ? "li" : $(this.container).children().get(0).tagName.toLowerCase()) : opts.tagName;
|
||||||
if (opts.itemSelector == "")
|
if (opts.itemSelector == "")
|
||||||
opts.itemSelector = opts.tagName;
|
opts.itemSelector = opts.tagName;
|
||||||
if (opts.dragSelector == "")
|
if (opts.dragSelector == "")
|
||||||
opts.dragSelector = opts.tagName;
|
opts.dragSelector = opts.tagName;
|
||||||
if (opts.placeHolderTemplate == "")
|
if (opts.placeHolderTemplate == "")
|
||||||
opts.placeHolderTemplate = "<" + opts.tagName + "> </" + opts.tagName + ">";
|
opts.placeHolderTemplate = "<" + opts.tagName + "> </" + opts.tagName + ">";
|
||||||
|
|
||||||
//listidx allows reference back to correct list variable instance
|
//listidx allows reference back to correct list variable instance
|
||||||
$(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit);
|
$(this.container).attr("data-listidx", i).mousedown(this.grabItem).bind("dragsort-uninit", this.uninit);
|
||||||
this.styleDragHandlers(true);
|
this.styleDragHandlers(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
uninit: function() {
|
uninit: function() {
|
||||||
var list = lists[$(this).attr("data-listidx")];
|
var list = lists[$(this).attr("data-listidx")];
|
||||||
$(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit");
|
$(list.container).unbind("mousedown", list.grabItem).unbind("dragsort-uninit");
|
||||||
list.styleDragHandlers(false);
|
list.styleDragHandlers(false);
|
||||||
},
|
},
|
||||||
|
|
||||||
getItems: function() {
|
getItems: function() {
|
||||||
return $(this.container).children(opts.itemSelector);
|
return $(this.container).children(opts.itemSelector);
|
||||||
},
|
},
|
||||||
|
|
||||||
styleDragHandlers: function(cursor) {
|
styleDragHandlers: function(cursor) {
|
||||||
this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : "");
|
this.getItems().map(function() { return $(this).is(opts.dragSelector) ? this : $(this).find(opts.dragSelector).get(); }).css("cursor", cursor ? "pointer" : "");
|
||||||
},
|
},
|
||||||
|
|
||||||
grabItem: function(e) {
|
grabItem: function(e) {
|
||||||
var list = lists[$(this).attr("data-listidx")];
|
var list = lists[$(this).attr("data-listidx")];
|
||||||
var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0);
|
var item = $(e.target).closest("[data-listidx] > " + opts.tagName).get(0);
|
||||||
var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0;
|
var insideMoveableItem = list.getItems().filter(function() { return this == item; }).size() > 0;
|
||||||
|
|
||||||
//if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return
|
//if not left click or if clicked on excluded element (e.g. text box) or not a moveable list item return
|
||||||
if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem)
|
if (e.which != 1 || $(e.target).is(opts.dragSelectorExclude) || $(e.target).closest(opts.dragSelectorExclude).size() > 0 || !insideMoveableItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved,
|
//prevents selection, stops issue on Fx where dragging hyperlink doesn't work and on IE where it triggers mousemove even though mouse hasn't moved,
|
||||||
//does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude
|
//does also stop being able to click text boxes hence dragging on text boxes by default is disabled in dragSelectorExclude
|
||||||
//e.preventDefault();
|
//e.preventDefault();
|
||||||
|
|
||||||
//change cursor to move while dragging
|
//change cursor to move while dragging
|
||||||
var dragHandle = e.target;
|
var dragHandle = e.target;
|
||||||
while (!$(dragHandle).is(opts.dragSelector)) {
|
while (!$(dragHandle).is(opts.dragSelector)) {
|
||||||
if (dragHandle == this) return;
|
if (dragHandle == this) return;
|
||||||
dragHandle = dragHandle.parentNode;
|
dragHandle = dragHandle.parentNode;
|
||||||
}
|
}
|
||||||
$(dragHandle).attr("data-cursor", $(dragHandle).css("cursor"));
|
$(dragHandle).attr("data-cursor", $(dragHandle).css("cursor"));
|
||||||
$(dragHandle).css("cursor", "move");
|
$(dragHandle).css("cursor", "move");
|
||||||
|
|
||||||
//on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work
|
//on mousedown wait for movement of mouse before triggering dragsort script (dragStart) to allow clicking of hyperlinks to work
|
||||||
var listElem = this;
|
var listElem = this;
|
||||||
var trigger = function() {
|
var trigger = function() {
|
||||||
list.dragStart.call(listElem, e);
|
list.dragStart.call(listElem, e);
|
||||||
$(list.container).unbind("mousemove", trigger);
|
$(list.container).unbind("mousemove", trigger);
|
||||||
};
|
};
|
||||||
$(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); });
|
$(list.container).mousemove(trigger).mouseup(function() { $(list.container).unbind("mousemove", trigger); $(dragHandle).css("cursor", $(dragHandle).attr("data-cursor")); });
|
||||||
},
|
},
|
||||||
|
|
||||||
dragStart: function(e) {
|
dragStart: function(e) {
|
||||||
if (list != null && list.draggedItem != null)
|
if (list != null && list.draggedItem != null)
|
||||||
list.dropItem();
|
list.dropItem();
|
||||||
|
|
||||||
list = lists[$(this).attr("data-listidx")];
|
list = lists[$(this).attr("data-listidx")];
|
||||||
list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName)
|
list.draggedItem = $(e.target).closest("[data-listidx] > " + opts.tagName)
|
||||||
|
|
||||||
//record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items
|
//record current position so on dragend we know if the dragged item changed position or not, not using getItems to allow dragsort to restore dragged item to original location in relation to fixed items
|
||||||
list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem));
|
list.draggedItem.attr("data-origpos", $(this).attr("data-listidx") + "-" + $(list.container).children().index(list.draggedItem));
|
||||||
|
|
||||||
//calculate mouse offset relative to draggedItem
|
//calculate mouse offset relative to draggedItem
|
||||||
var mt = parseInt(list.draggedItem.css("marginTop"));
|
var mt = parseInt(list.draggedItem.css("marginTop"));
|
||||||
var ml = parseInt(list.draggedItem.css("marginLeft"));
|
var ml = parseInt(list.draggedItem.css("marginLeft"));
|
||||||
list.offset = list.draggedItem.offset();
|
list.offset = list.draggedItem.offset();
|
||||||
list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
|
list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
|
||||||
list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;
|
list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;
|
||||||
|
|
||||||
//calculate box the dragged item can't be dragged outside of
|
//calculate box the dragged item can't be dragged outside of
|
||||||
if (!opts.dragBetween) {
|
if (!opts.dragBetween) {
|
||||||
var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight();
|
var containerHeight = $(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + list.getItems().size() * list.draggedItem.outerWidth() / $(list.container).outerWidth())) * list.draggedItem.outerHeight() : $(list.container).outerHeight();
|
||||||
list.offsetLimit = $(list.container).offset();
|
list.offsetLimit = $(list.container).offset();
|
||||||
list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth();
|
list.offsetLimit.right = list.offsetLimit.left + $(list.container).outerWidth() - list.draggedItem.outerWidth();
|
||||||
list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
|
list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
//create placeholder item
|
//create placeholder item
|
||||||
var h = list.draggedItem.height();
|
var h = list.draggedItem.height();
|
||||||
var w = list.draggedItem.width();
|
var w = list.draggedItem.width();
|
||||||
if (opts.tagName == "tr") {
|
if (opts.tagName == "tr") {
|
||||||
list.draggedItem.children().each(function() { $(this).width($(this).width()); });
|
list.draggedItem.children().each(function() { $(this).width($(this).width()); });
|
||||||
list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true);
|
list.placeHolderItem = list.draggedItem.clone().attr("data-placeholder", true);
|
||||||
list.draggedItem.after(list.placeHolderItem);
|
list.draggedItem.after(list.placeHolderItem);
|
||||||
//list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); });
|
//list.placeHolderItem.children().each(function() { $(this).css({ borderWidth:0, width: $(this).width() + 1, height: $(this).height() + 1 }).html(" "); });
|
||||||
list.placeHolderItem.children().each(function() { $(this).html(" "); });
|
list.placeHolderItem.children().each(function() { $(this).html(" "); });
|
||||||
} else {
|
} else {
|
||||||
list.draggedItem.after(opts.placeHolderTemplate);
|
list.draggedItem.after(opts.placeHolderTemplate);
|
||||||
list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true);
|
list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeholder", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.tagName == "td") {
|
if (opts.tagName == "td") {
|
||||||
var listTable = list.draggedItem.closest("table").get(0);
|
var listTable = list.draggedItem.closest("table").get(0);
|
||||||
$("<table id='" + listTable.id + "' style='border-width: 0px;' class='dragSortItem " + listTable.className + "'><tr></tr></table>").appendTo("body").children().append(list.draggedItem);
|
$("<table id='" + listTable.id + "' style='border-width: 0px;' class='dragSortItem " + listTable.className + "'><tr></tr></table>").appendTo("body").children().append(list.draggedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
//style draggedItem while dragging
|
//style draggedItem while dragging
|
||||||
var orig = list.draggedItem.attr("style");
|
var orig = list.draggedItem.attr("style");
|
||||||
list.draggedItem.attr("data-origstyle", orig ? orig : "");
|
list.draggedItem.attr("data-origstyle", orig ? orig : "");
|
||||||
list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });
|
list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });
|
||||||
|
|
||||||
//auto-scroll setup
|
//auto-scroll setup
|
||||||
list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() };
|
list.scroll = { moveX: 0, moveY: 0, maxX: $(document).width() - $(window).width(), maxY: $(document).height() - $(window).height() };
|
||||||
list.scroll.scrollY = window.setInterval(function() {
|
list.scroll.scrollY = window.setInterval(function() {
|
||||||
if (opts.scrollContainer != window) {
|
if (opts.scrollContainer != window) {
|
||||||
$(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY);
|
$(opts.scrollContainer).scrollTop($(opts.scrollContainer).scrollTop() + list.scroll.moveY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var t = $(opts.scrollContainer).scrollTop();
|
var t = $(opts.scrollContainer).scrollTop();
|
||||||
if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
|
if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
|
||||||
$(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
|
$(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
|
||||||
list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
|
list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
|
||||||
}
|
}
|
||||||
}, 10);
|
}, 10);
|
||||||
list.scroll.scrollX = window.setInterval(function() {
|
list.scroll.scrollX = window.setInterval(function() {
|
||||||
if (opts.scrollContainer != window) {
|
if (opts.scrollContainer != window) {
|
||||||
$(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
|
$(opts.scrollContainer).scrollLeft($(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var l = $(opts.scrollContainer).scrollLeft();
|
var l = $(opts.scrollContainer).scrollLeft();
|
||||||
if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
|
if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
|
||||||
$(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
|
$(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
|
||||||
list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
|
list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
|
||||||
}
|
}
|
||||||
}, 10);
|
}, 10);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
$(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
|
$(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
|
||||||
list.setPos(e.pageX, e.pageY);
|
list.setPos(e.pageX, e.pageY);
|
||||||
$(document).bind("mousemove", list.swapItems);
|
$(document).bind("mousemove", list.swapItems);
|
||||||
$(document).bind("mouseup", list.dropItem);
|
$(document).bind("mouseup", list.dropItem);
|
||||||
if (opts.scrollContainer != window)
|
if (opts.scrollContainer != window)
|
||||||
$(window).bind("wheel", list.wheel);
|
$(window).bind("wheel", list.wheel);
|
||||||
},
|
},
|
||||||
|
|
||||||
//set position of draggedItem
|
//set position of draggedItem
|
||||||
setPos: function(x, y) {
|
setPos: function(x, y) {
|
||||||
//remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner
|
//remove mouse offset so mouse cursor remains in same place on draggedItem instead of top left corner
|
||||||
var top = y - this.offset.top;
|
var top = y - this.offset.top;
|
||||||
var left = x - this.offset.left;
|
var left = x - this.offset.left;
|
||||||
|
|
||||||
//limit top, left to within box draggedItem can't be dragged outside of
|
//limit top, left to within box draggedItem can't be dragged outside of
|
||||||
if (!opts.dragBetween) {
|
if (!opts.dragBetween) {
|
||||||
top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
|
top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
|
||||||
left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
|
left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
|
||||||
}
|
}
|
||||||
|
|
||||||
//adjust top & left calculations to parent offset
|
//adjust top & left calculations to parent offset
|
||||||
var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin
|
var parent = this.draggedItem.offsetParent().not("body").offset(); //offsetParent returns body even when it's static, if not static offset is only factoring margin
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
top -= parent.top;
|
top -= parent.top;
|
||||||
left -= parent.left;
|
left -= parent.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
//set x or y auto-scroll amount
|
//set x or y auto-scroll amount
|
||||||
if (opts.scrollContainer == window) {
|
if (opts.scrollContainer == window) {
|
||||||
y -= $(window).scrollTop();
|
y -= $(window).scrollTop();
|
||||||
x -= $(window).scrollLeft();
|
x -= $(window).scrollLeft();
|
||||||
y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5);
|
y = Math.max(0, y - $(window).height() + 5) + Math.min(0, y - 5);
|
||||||
x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5);
|
x = Math.max(0, x - $(window).width() + 5) + Math.min(0, x - 5);
|
||||||
} else {
|
} else {
|
||||||
var cont = $(opts.scrollContainer);
|
var cont = $(opts.scrollContainer);
|
||||||
var offset = cont.offset();
|
var offset = cont.offset();
|
||||||
y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
|
y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
|
||||||
x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
|
x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
|
||||||
}
|
}
|
||||||
|
|
||||||
list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
|
list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
|
||||||
list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);
|
list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);
|
||||||
|
|
||||||
//move draggedItem to new mouse cursor location
|
//move draggedItem to new mouse cursor location
|
||||||
this.draggedItem.css({ top: top, left: left });
|
this.draggedItem.css({ top: top, left: left });
|
||||||
},
|
},
|
||||||
|
|
||||||
//if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over
|
//if scroll container is a div allow mouse wheel to scroll div instead of window when mouse is hovering over
|
||||||
wheel: function(e) {
|
wheel: function(e) {
|
||||||
if (list && opts.scrollContainer != window) {
|
if (list && opts.scrollContainer != window) {
|
||||||
var cont = $(opts.scrollContainer);
|
var cont = $(opts.scrollContainer);
|
||||||
var offset = cont.offset();
|
var offset = cont.offset();
|
||||||
e = e.originalEvent;
|
e = e.originalEvent;
|
||||||
if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) {
|
if (e.clientX > offset.left && e.clientX < offset.left + cont.width() && e.clientY > offset.top && e.clientY < offset.top + cont.height()) {
|
||||||
var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY;
|
var deltaY = (e.deltaMode == 0 ? 1 : 10) * e.deltaY;
|
||||||
cont.scrollTop(cont.scrollTop() + deltaY);
|
cont.scrollTop(cont.scrollTop() + deltaY);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//build a table recording all the positions of the moveable list items
|
//build a table recording all the positions of the moveable list items
|
||||||
buildPositionTable: function() {
|
buildPositionTable: function() {
|
||||||
var pos = [];
|
var pos = [];
|
||||||
this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) {
|
this.getItems().not([list.draggedItem[0], list.placeHolderItem[0]]).each(function(i) {
|
||||||
var loc = $(this).offset();
|
var loc = $(this).offset();
|
||||||
loc.right = loc.left + $(this).outerWidth();
|
loc.right = loc.left + $(this).outerWidth();
|
||||||
loc.bottom = loc.top + $(this).outerHeight();
|
loc.bottom = loc.top + $(this).outerHeight();
|
||||||
loc.elm = this;
|
loc.elm = this;
|
||||||
pos[i] = loc;
|
pos[i] = loc;
|
||||||
});
|
});
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
dropItem: function() {
|
dropItem: function() {
|
||||||
if (list.draggedItem == null)
|
if (list.draggedItem == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
|
//list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
|
||||||
//list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
|
//list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
|
||||||
var orig = list.draggedItem.attr("data-origstyle");
|
var orig = list.draggedItem.attr("data-origstyle");
|
||||||
list.draggedItem.attr("style", orig);
|
list.draggedItem.attr("style", orig);
|
||||||
if (orig == "")
|
if (orig == "")
|
||||||
list.draggedItem.removeAttr("style");
|
list.draggedItem.removeAttr("style");
|
||||||
list.draggedItem.removeAttr("data-origstyle");
|
list.draggedItem.removeAttr("data-origstyle");
|
||||||
|
|
||||||
list.styleDragHandlers(true);
|
list.styleDragHandlers(true);
|
||||||
|
|
||||||
list.placeHolderItem.before(list.draggedItem);
|
list.placeHolderItem.before(list.draggedItem);
|
||||||
list.placeHolderItem.remove();
|
list.placeHolderItem.remove();
|
||||||
|
|
||||||
$("[data-droptarget], .dragSortItem").remove();
|
$("[data-droptarget], .dragSortItem").remove();
|
||||||
|
|
||||||
window.clearInterval(list.scroll.scrollY);
|
window.clearInterval(list.scroll.scrollY);
|
||||||
window.clearInterval(list.scroll.scrollX);
|
window.clearInterval(list.scroll.scrollX);
|
||||||
|
|
||||||
//if position changed call dragEnd
|
//if position changed call dragEnd
|
||||||
if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem))
|
if (list.draggedItem.attr("data-origpos") != $(lists).index(list) + "-" + $(list.container).children().index(list.draggedItem))
|
||||||
if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order
|
if (opts.dragEnd.apply(list.draggedItem) == false) { //if dragEnd returns false revert order
|
||||||
var pos = list.draggedItem.attr("data-origpos").split('-');
|
var pos = list.draggedItem.attr("data-origpos").split('-');
|
||||||
var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]);
|
var nextItem = $(lists[pos[0]].container).children().not(list.draggedItem).eq(pos[1]);
|
||||||
if (nextItem.size() > 0)
|
if (nextItem.size() > 0)
|
||||||
nextItem.before(list.draggedItem);
|
nextItem.before(list.draggedItem);
|
||||||
else if (pos[1] == 0) //was the only item in list
|
else if (pos[1] == 0) //was the only item in list
|
||||||
$(lists[pos[0]].container).prepend(list.draggedItem);
|
$(lists[pos[0]].container).prepend(list.draggedItem);
|
||||||
else //was the last item in list
|
else //was the last item in list
|
||||||
$(lists[pos[0]].container).append(list.draggedItem);
|
$(lists[pos[0]].container).append(list.draggedItem);
|
||||||
}
|
}
|
||||||
list.draggedItem.removeAttr("data-origpos");
|
list.draggedItem.removeAttr("data-origpos");
|
||||||
|
|
||||||
list.draggedItem = null;
|
list.draggedItem = null;
|
||||||
$(document).unbind("mousemove", list.swapItems);
|
$(document).unbind("mousemove", list.swapItems);
|
||||||
$(document).unbind("mouseup", list.dropItem);
|
$(document).unbind("mouseup", list.dropItem);
|
||||||
if (opts.scrollContainer != window)
|
if (opts.scrollContainer != window)
|
||||||
$(window).unbind("wheel", list.wheel);
|
$(window).unbind("wheel", list.wheel);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
//swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of
|
//swap the draggedItem (represented visually by placeholder) with the list item the it has been dragged on top of
|
||||||
swapItems: function(e) {
|
swapItems: function(e) {
|
||||||
if (list.draggedItem == null)
|
if (list.draggedItem == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//move draggedItem to mouse location
|
//move draggedItem to mouse location
|
||||||
list.setPos(e.pageX, e.pageY);
|
list.setPos(e.pageX, e.pageY);
|
||||||
|
|
||||||
//retrieve list and item position mouse cursor is over
|
//retrieve list and item position mouse cursor is over
|
||||||
var ei = list.findPos(e.pageX, e.pageY);
|
var ei = list.findPos(e.pageX, e.pageY);
|
||||||
var nlist = list;
|
var nlist = list;
|
||||||
for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) {
|
for (var i = 0; ei == -1 && opts.dragBetween && i < lists.length; i++) {
|
||||||
ei = lists[i].findPos(e.pageX, e.pageY);
|
ei = lists[i].findPos(e.pageX, e.pageY);
|
||||||
nlist = lists[i];
|
nlist = lists[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
//if not over another moveable list item return
|
//if not over another moveable list item return
|
||||||
if (ei == -1)
|
if (ei == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//save fixed items locations
|
//save fixed items locations
|
||||||
var children = function() { return $(nlist.container).children().not(nlist.draggedItem); };
|
var children = function() { return $(nlist.container).children().not(nlist.draggedItem); };
|
||||||
var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); });
|
var fixed = children().not(opts.itemSelector).each(function(i) { this.idx = children().index(this); });
|
||||||
|
|
||||||
//if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after
|
//if moving draggedItem up or left place placeHolder before list item the dragged item is hovering over otherwise place it after
|
||||||
if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left)
|
if (lastPos == null || lastPos.top > list.draggedItem.offset().top || lastPos.left > list.draggedItem.offset().left)
|
||||||
$(nlist.pos[ei].elm).before(list.placeHolderItem);
|
$(nlist.pos[ei].elm).before(list.placeHolderItem);
|
||||||
else
|
else
|
||||||
$(nlist.pos[ei].elm).after(list.placeHolderItem);
|
$(nlist.pos[ei].elm).after(list.placeHolderItem);
|
||||||
|
|
||||||
//restore fixed items location
|
//restore fixed items location
|
||||||
fixed.each(function() {
|
fixed.each(function() {
|
||||||
var elm = children().eq(this.idx).get(0);
|
var elm = children().eq(this.idx).get(0);
|
||||||
if (this != elm && children().index(this) < this.idx)
|
if (this != elm && children().index(this) < this.idx)
|
||||||
$(this).insertAfter(elm);
|
$(this).insertAfter(elm);
|
||||||
else if (this != elm)
|
else if (this != elm)
|
||||||
$(this).insertBefore(elm);
|
$(this).insertBefore(elm);
|
||||||
});
|
});
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
$(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
|
$(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });
|
||||||
lastPos = list.draggedItem.offset();
|
lastPos = list.draggedItem.offset();
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
//returns the index of the list item the mouse is over
|
//returns the index of the list item the mouse is over
|
||||||
findPos: function(x, y) {
|
findPos: function(x, y) {
|
||||||
for (var i = 0; i < this.pos.length; i++) {
|
for (var i = 0; i < this.pos.length; i++) {
|
||||||
if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y)
|
if (this.pos[i].left < x && this.pos[i].right > x && this.pos[i].top < y && this.pos[i].bottom > y)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
//create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position
|
//create drop targets which are placeholders at the end of other lists to allow dragging straight to the last position
|
||||||
createDropTargets: function() {
|
createDropTargets: function() {
|
||||||
if (!opts.dragBetween)
|
if (!opts.dragBetween)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$(lists).each(function() {
|
$(lists).each(function() {
|
||||||
var ph = $(this.container).find("[data-placeholder]");
|
var ph = $(this.container).find("[data-placeholder]");
|
||||||
var dt = $(this.container).find("[data-droptarget]");
|
var dt = $(this.container).find("[data-droptarget]");
|
||||||
if (ph.size() > 0 && dt.size() > 0)
|
if (ph.size() > 0 && dt.size() > 0)
|
||||||
dt.remove();
|
dt.remove();
|
||||||
else if (ph.size() == 0 && dt.size() == 0) {
|
else if (ph.size() == 0 && dt.size() == 0) {
|
||||||
if (opts.tagName == "td")
|
if (opts.tagName == "td")
|
||||||
$(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container);
|
$(opts.placeHolderTemplate).attr("data-droptarget", true).appendTo(this.container);
|
||||||
else
|
else
|
||||||
//list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8)
|
//list.placeHolderItem.clone().removeAttr("data-placeholder") crashes in IE7 and jquery 1.5.1 (doesn't in jquery 1.4.2 or IE8)
|
||||||
$(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true));
|
$(this.container).append(list.placeHolderItem.removeAttr("data-placeholder").clone().attr("data-droptarget", true));
|
||||||
|
|
||||||
list.placeHolderItem.attr("data-placeholder", true);
|
list.placeHolderItem.attr("data-placeholder", true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
newList.init();
|
newList.init();
|
||||||
lists.push(newList);
|
lists.push(newList);
|
||||||
});
|
});
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
$.fn.dragsort.defaults = {
|
$.fn.dragsort.defaults = {
|
||||||
tagName:"",
|
tagName:"",
|
||||||
itemSelector: "",
|
itemSelector: "",
|
||||||
dragSelector: "",
|
dragSelector: "",
|
||||||
dragSelectorExclude: "input, textarea",
|
dragSelectorExclude: "input, textarea",
|
||||||
dragEnd: function() { },
|
dragEnd: function() { },
|
||||||
dragBetween: false,
|
dragBetween: false,
|
||||||
placeHolderTemplate: "",
|
placeHolderTemplate: "",
|
||||||
scrollContainer: window,
|
scrollContainer: window,
|
||||||
scrollSpeed: 5
|
scrollSpeed: 5
|
||||||
};
|
};
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
|
||||||
define("dragsort", function(){});
|
define("dragsort", function(){});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
|
||||||
},
|
},
|
||||||
ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列
|
ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列
|
||||||
},
|
},
|
||||||
pageSize: localStorage.getItem("pagesize") || 10,
|
pageSize: localStorage.getItem('page-size') || 10,
|
||||||
pageList: [10, 15, 20, 25, 50, 'All'],
|
pageList: [10, 15, 20, 25, 50, 'All'],
|
||||||
pagination: true,
|
pagination: true,
|
||||||
clickToSelect: true, //是否启用点击选中
|
clickToSelect: true, //是否启用点击选中
|
||||||
|
|
@ -190,12 +190,6 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
|
||||||
table.on('refresh.bs.table', function (e, settings, data) {
|
table.on('refresh.bs.table', function (e, settings, data) {
|
||||||
$(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin");
|
$(Table.config.refreshbtn, toolbar).find(".fa").addClass("fa-spin");
|
||||||
});
|
});
|
||||||
//当表格分页变更时
|
|
||||||
table.on('page-change.bs.table', function (e, page, pagesize) {
|
|
||||||
if (!isNaN(pagesize)) {
|
|
||||||
localStorage.setItem("pagesize", pagesize);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
//当执行搜索时
|
//当执行搜索时
|
||||||
table.on('search.bs.table common-search.bs.table', function (e, settings, data) {
|
table.on('search.bs.table common-search.bs.table', function (e, settings, data) {
|
||||||
table.trigger("uncheckbox");
|
table.trigger("uncheckbox");
|
||||||
|
|
@ -540,6 +534,12 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
|
||||||
Table.list[id] = table;
|
Table.list[id] = table;
|
||||||
return table;
|
return table;
|
||||||
},
|
},
|
||||||
|
// 设置全局分页的单页显示数
|
||||||
|
pageSize: function (pageSize) {
|
||||||
|
if (!isNaN(pageSize)) {
|
||||||
|
localStorage.setItem('page-size', pageSize);
|
||||||
|
}
|
||||||
|
},
|
||||||
// 批量操作请求
|
// 批量操作请求
|
||||||
multi: function (action, ids, table, element) {
|
multi: function (action, ids, table, element) {
|
||||||
var options = table.bootstrapTable('getOptions');
|
var options = table.bootstrapTable('getOptions');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue