我们正在使用backbone.paginator
; backgrid
; backgrid-filter
; backgrid-paginator
它很有效我们在尝试排序时遇到小问题 - 在server side mode
- 网格一列(或多列)
对于正在使用Spring
org.springframework.data.web.PageableHandlerMethodArgumentResolver
在调试应用程序时,似乎来自客户端的order
在弹簧方面没有得到很好的解析而且它落到了default value
PageableHandlerMethodArgumentResolver
的参数是什么?Backbone.PageableCollection
如何进行调整?谢谢, 橡木
Backbone.PageableCollection.extend({
state : {
pageSize : 15,
firstPage : 0, /* Spring paging is 0-based */
},
mode : "server",
/**
* override default queryParams to fit spring pageable var names
*/
queryParams : {
pageSize:"size",
totalRecords:"totalElements",
sortKey:"sort",
order:"sort_order",
directions : { "-1": "asc", "1": "desc" }
},
})
P.S:
似乎spring
期望将data
数组分隔为comma
而不是常规。任何想法如何与backbone.paginator
?或者如何更改spring以便能够解析paginator以支持几个`排序参数
答案 0 :(得分:1)
在Spring源PageableHandlerMethodArgumentResolver
和SortHandlerMethodArgumentResolver.java
(可以找到here)进行一些挖掘之后,看起来Spring希望排序参数的格式为
sort="column1,column2,column3...,order"&sort="column4,column5,...,order"
似乎backbone.paginator
不支持多重排序,但为了使paginator
支持SortHandlerMethodArgumentResolver
单一排序,可以覆盖sync
函数来设置变量
var sync = Backbone.PageableCollection.prototype.sync;
Backbone.PageableCollection.prototype.sync = function(method, model,
options) {
options.type = 'POST' // this help with unicode on tomcat and can be removed..
/**
* @override sync Add some code to support parsing of sorting parameters
* by SortHandlerMethodArgumentResolver
*/
if (!options.data) {
sync.apply(this, arguments)
}
var sortKey = _.result(this.queryParams,"sortKey");
if (!sortKey in options.data) {
sync.apply(this, arguments)
}
options.data[STR_SPRING_SORT] = options.data[sortKey]
var orderKey = _.result(this.queryParams,"order");
var STR_SPRING_SORT = "sort";
var STR_SEPERATOR = ",";
if (orderKey in options.data) {
options.data[STR_SPRING_SORT] = options.data[STR_SPRING_SORT] + STR_SEPERATOR
+ options.data[orderKey]
if (sortKey !== STR_SPRING_SORT) {
delete options.data[sortKey];
}
delete options.data["order"];
}
sync.apply(this, arguments);
};
可以强制弹簧更改comma
和sort
字符串。