我需要在我的网格中添加排序和过滤。网格是选项卡面板的一部分。我可以在 Firebug 中看到调用控制器的以下参数:
_dc 1361741346485
limit 200
page 2
sort [{"property":"IsLate","direction":"ASC"}]
start 200
我需要向控制器方法添加哪些参数才能接受来自请求的排序参数?我想我需要序列化它。我试图创建一个具有属性和方向的排序对象,但是当我调试时,接收到的参数的属性和方向为空。我需要遵循命名约定吗?我很困惑。谢谢你。
这是我的代码:
LateGrid.js
Ext.define('FICMTB.ui.LateModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'Id' },
{ name: 'IsLate' },
{ name: 'Comments' },
{ name: 'Description' }],
idProperty: 'Id'
});
Ext.define("FICMTB.ui.LateGrid", {
extend: "Ext.grid.Panel",
requires: [
'FICMTB.ui.LateModel',
'Ext.ux.grid.FiltersFeature'
],
initComponent: function () {
var me = this;
me.columns = me.buildColumns();
me.filters = {
ftype: 'filters',
encode: false, // json encode the filter query
filters: [{
options: ['YES', 'NO'],
dataIndex: 'IsLate'
}]
};
me.features = [me.filters];
me.store = Ext.create('Ext.data.Store', {
model: 'FICMTB.ui.LateModel',
remoteSort: true,
storeId: 'LateStoreId',
autoLoad: true,
buffered: true,
autoSync: true,
pageSize: 200,
proxy: {
type: 'rest',
timeout: 600000,
url: '/Late/Transactions/',
reader: {
type: 'json',
root: 'transactions',
totalProperty: "Total"
},
writer: {
type: 'json',
root: 'transactions'
}
}
});
me.selModel = new Ext.selection.RowModel({
singleSelect: true
});
me.autoSizeColumns = true;
me.autoScroll = true;
me.forcefit = true;
me.callParent(arguments);
},
buildColumns: function () {
var me = this;
return [
{ text: 'Id', dataIndex: 'Id', hidden: true, hideable: false },
{ text: 'Is Late' dataIndex: 'IsLate', sortable: true, width: 50, filter:true},
{ text: 'Comments', dataIndex: 'Comments', width: 250, sortable: true },
{ text: 'Description', dataIndex: 'Description', width: 250, sortable: true }];
},
height: 600,
width: 'auto'
});
后期控制器.cs
[AcceptVerbs(HttpVerbs.Get)]
[ActionName("LateTransactions")]
public ActionResult GetLateTransactions(string page, string start, string limit, xxxxxx sorting, yyyyy filtering)
{
// what should xxxxx and yyyyy be? how should I name the sorting and filtering parameters?
// returns json
}
编辑:我尝试使用 Sorting 对象,但它是 null
// Sorting
// NOT Simple Sort:
// Request: index?sort=[{"property":"email","direction":"DESC"}, {"property":"last_name","direction":"ASC"}, ...]
public class Sorting
{
public string property { set; get; }
public string direction { set; get; }
}
[AcceptVerbs(HttpVerbs.Get)]
[ActionName("LateTransactions")]
public ActionResult GetLateTransactions(string page, string start, string limit, Sorting sort, yyyyy filtering)
{
....
}