我使用kendo ui grid(对于asp.net mvc)没有问题,如果我声明dataSource传输读取为url,如:
var dataSource = {
pageSize: 20,
batch: true,
serverOperation: true,
serverPaging: true,
serverSorting: true,
serverFiltering: true,
type: "aspnetmvc-ajax",
transport:
{
read:
{
url: '/Home/GetNodes',
type: "POST",
dataType: "json",
data: function ()
{
return {'p1': 'some text', 'p2': 'other'}
}
}
}
};
现在的问题是我想要使用功能模式读取(是软件设计要求) 但是用于将请求参数传递给服务器的sintax与使用传输类型不同#34; aspnetmvc-ajax"或不。 如果我设置传输类型" aspnetmvc-ajax"读取函数未被触发, 但如果没有设置运输类型" aspnetmvc-ajax"请求参数在服务器端没有很好地传递!
如果我观看通过http发送的帖子参数:
使用传输类型" aspnetmvc-ajax":
page:1
pageSize:20
sort:Field1-asc
filter:Field1~eq~'value1'
没有传输类型" aspnetmvc-ajax":
page:1
pageSize:20
sort:[{field:Field1, dir:asc}]
filter:{filters:[{operator:eq, value:value1, field:Field1}], logic:and}
排序和过滤值参数与" aspnetmvc-ajax"不同。版本和服务器端都是null!
作为解决方法我手动解析parameterMap中的请求参数,如底部所示, 翻译排序和过滤值sintax符合" aspnetmvc-ajax"版本和服务器端都通过了。
感谢
我的解决方法是:
var dataSource = {
pageSize: 20,
batch: true,
serverOperation: true,
serverPaging: true,
serverSorting: true,
serverFiltering: true,
transport:
{
read: function (options)
{
var request = $scope.grdDocuments.dataSource.transport.parameterMap({
filter: $scope.grdDocuments.dataSource.filter(),
group: $scope.grdDocuments.dataSource.group(),
sort: $scope.grdDocuments.dataSource.sort(),
page: $scope.grdDocuments.dataSource.page(),
pageSize: $scope.grdDocuments.dataSource.pageSize()
});
httpService.GetNodes(request.filter, request.group, request.sort, request.page, request.pageSize, sFolderId, ... other parameters)
.then(
function (args)
{
//Verifica esito della richiesta http
if (!sharedService.CheckHttpRequestResult(args, 'GetNodes'))
{
options.error(null);
return;
}
options.success(args.data);
}
);
},
parameterMap: function (data, operation)
{
//Trasformazione parametro filter
if (typeof data.filter !== 'undefined')
{
//normale: {filters:[{operator:eq, value:a, field:Affidatario}], logic:and}
//trasformato: Affidatario~eq~'a'
var filter = '';
for (var i = 0; i < data.filter.filters.length; i++)
{
if (filter !== '')
filter += '~' + data.filter.logic + '~';
var fieldValue = "'" + data.filter.filters[i].value + "'";
//Formattazione valore in base al formato della colonna
var found = model.fields[data.filter.filters[i].field];
if (typeof found !== 'undefined')
{
if (found.type === 'number')
fieldValue = data.filter.filters[i].value;
else if (found.type === 'date')
fieldValue = "datetime'" + data.filter.filters[i].value.format('Y-m-d') + "T00-00-00'";
}
filter += data.filter.filters[i].field + '~' + data.filter.filters[i].operator + '~' + fieldValue;
}
data.filter = filter;
}
//Trasformazione parametro sort
if (typeof data.sort !== 'undefined')
{
//normale: [{field:Anno, dir:asc}]
//trasformato: Anno-asc
var sort = '';
for (var i = 0; i < data.sort.length; i++)
{
if (sort !== '')
sort += '~';
sort += data.sort[i].field + '-' + data.sort[i].dir;
}
data.sort = sort;
}
var result = JSON.parse(JSON.stringify(data));
return result;
}
}
};
服务器端:
public JsonResult GetNodes([DataSourceRequest]DataSourceRequest request, string sFolderId, ... other parameters)
{
}
答案 0 :(得分:0)
以防其他人像我今天一样偶然发现这篇文章。 This might help you
对我来说答案就是
行var data = kendo.data.transports["aspnetmvc-ajax"].prototype.options.parameterMap.call(this, optionsData.data, "read", false);