我需要添加排序和過濾到我的網格。網格是選項卡面板的一部分。我可以在螢火蟲看到下面的參數來調用控制器:extjs 4.1遠程網格排序和MVC過濾
_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'
});
LateController.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
// 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)
{
....
}
在你的動作參數過濾器,不應該是類型的字符串?您好像正在接收Filtering,然後將其反序列化爲列表。 –
2013-03-28 17:09:53