我有一个kendoGrid
,我想获得的JSON
过滤和排序我怎么做到这一点后,出来的吗?
类似于下面的东西,
var grid = $("#grid").data("kendoGrid");
alert(grid.dataSource.data.json); // I could dig through grid.dataSource.data and I see a function ( .json doen't exist I put it there so you know what i want to achieve )
感谢任何帮助是极大的赞赏!
我认为你正在寻找
var displayedData = $("#YourGrid").data().kendoGrid.dataSource.view()
然后如下字符串化它:
var displayedDataAsJSON = JSON.stringify(displayedData);
希望这可以帮助!
如果你想获得您可以使用此过滤的数据的所有页面:
var dataSource = $("#grid").data("kendoGrid").dataSource;
var filters = dataSource.filter();
var allData = dataSource.data();
var query = new kendo.data.Query(allData);
var data = query.filter(filters).data;
请务必检查是否试图应用这些或剑道会抱怨之前存在的过滤器。
为了获得在网格中的所有行数
$('#YourGridName').data("kendoGrid").dataSource.total()
为了获得特定行项目
$('#YourGridName').data("kendoGrid").dataSource.data()[1]
为了获得在网格中的所有行
$('#YourGridName').data("kendoGrid").dataSource.data()
JSON来在网格中的所有行
JSON.stringify($('#YourGridName').data("kendoGrid").dataSource.data())
像这样的事情,仅显示此刻正在被查看的数据。 还延长了电网遍布应用程序提供这些功能。
/**
* Extends kendo grid to return current displayed data
* on a 2-dimensional array
*/
var KendoGrid = window.kendo.ui.Grid;
KendoGrid.fn.getDisplayedData = function(){
var items = this.items();
var displayedData = new Array();
$.each(items,function(key, value) {
var dataItem = new Array();
$(value).find('td').each (function() {
var td = $(this);
if(!td.is(':visible')){
//element isn't visible, don't show
return;//continues to next element, that is next td
}
if(td.children().length == 0){
//if no children get text
dataItem.push(td.text());
} else{
//if children, find leaf child, where its text is the td content
var leafElement = innerMost($(this));
dataItem.push(leafElement.text());
}
});
displayedData.push(dataItem);
});
return displayedData;
};
KendoGrid.fn.getDisplayedColumns = function(){
var grid = this.element;
var displayedColumns = new Array();
$(grid).find('th').each(function(){
var th = $(this);
if(!th.is(':visible')){
//element isn't visible, don't show
return;//continues to next element, that is next th
}
//column is either k-link or plain text like <th>Column</th>
//so we extract text using this if:
var kLink = th.find(".k-link")[0];
if(kLink){
displayedColumns.push(kLink.text);
} else{
displayedColumns.push(th.text());
}
});
return displayedColumns;
};
/**
* Finds the leaf node of an HTML structure
*/
function innerMost( root ) {
var $children = $( root ).children();
while ( true ) {
var $temp = $children.children();
if($temp.length > 0) $children = $temp;
else return $children;
}
}
对于JSON的一部分,有一个辅助函数来提取JSON格式,可以帮助数据:
var displayedData = $("#YourGrid").data().kendoGrid.dataSource.view().toJSON()
编辑:由于剑道格行为的一些错误,上面的方法后,我发现在这篇文章中解决了这个问题: 剑道数据源视图中不总是返回observablearray