take a look at these 2 fiddles
http://jsfiddle.net/uFcHK/
(v2013.1.319)
http://jsfiddle.net/rcvY3/
(v2013.2.716)
The code is identical.
var grid = $("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.kendoui.com/service/Northwind.svc/Products"
},
pageSize: 15,
serverPaging: true,
serverSorting: true,
serverFiltering: true
},
height: 450,
sortable: true,
pageable: true,
editable: true,
toolbar: ["create"],
filterable: false,
columns: ["ProductID", "ProductName", "UnitPrice"]
});
(you can ignore the the broken nav panel, I don't see this in prod)
The problem is the record count.
If you click on "Add new record" you will see the record count do a text add instead of number add. This is crazy, no idea how kendo let this slide for half a year+
The problem is with OData that return total as string since this is received as string.
In previous releases of code the increment was done as total++ but now it is being added a number allowing to add more than one record in one single operation. The problem is that if you do string + number you actually get the number concatenated to the string.
The easiest way of solving it is providing a total function that just converts the string to number something as simple as defining in the DataSource:
dataSource: {
type : "odata",
transport : {
read: "http://demos.kendoui.com/service/Northwind.svc/Products"
},
schema : {
total : function (data) {
// Convert __count to number
return +data.d.__count;
}
},
pageSize : 15,
serverPaging : true,
serverSorting : true,
serverFiltering: true
},
Related
I am creating a kendo grid that is built out by calling an remote data source. I have enabled grouping, which works as expected, but I would like to default grouping and leave the user the option of adding/changing the groupings. I added the group parameter to the data source and this adds the desired group by default, but it also causes all column headers to disappear which prevents the end user from having the ability to add/change the groupings and also makes it a bit harder to read the displayed data. Google has failed me, so I submit myself to the mercy of stack overflow.
<div id="grid"></div>
<script>
var remoteDataSource = new kendo.data.DataSource({
transport: {
read: {
url: "https://localhost:44387/api/values",
dataType: "json"
}
},
pageSize: 8
,group: { field: "State" }
});
$("#grid").kendoGrid({
toolbar: ["excel", "pdf"],
groupable: true,
sortable: true,
pageable: {
pageSize: 5,
buttonCount: 10,
pageSizes: true
},
excel: {
allPages: true
},
pdf: {
allPages: true,
landscape: true
},
selectable: {
mode: "multiple, row"
},
reorderable: {
columns: true
},
dataSource: remoteDataSource,
height: 800,
width: 2000
});
</script>
Without default grouping:No Default Group
With default grouping: With Default Group
The reason is because you're allowing the grid to implicitly create the columns. If you explicitly define them, then they will show up.
See this example with the implicit column definition: https://dojo.telerik.com/AMucoVav versus this example with the explicit column definitions: https://dojo.telerik.com/EjeGeHAJ
I am loading a Kendo UI grid with virtual scrolling option on and for un-identified reasons when I scroll down when inside the grid infinite hits are made to the get grid data method.
My page also has angular JS.
The page number is always sent as one, but it should at least be incremented to two.
Grid has been defined as following:
dataSource: {
serverPaging: true,
serverSorting: true,
serverFiltering: true,
pageSize: 10,
transport: {
read: URL
},
schema: {
data: function(data) {
/* Few business filter operation done here */
return data.Items;
},
total: function(data) {
if (data.Items != null && data.Items.length > 0) {
// Every record of the current data set has total employees count
// Thus returning the first value
return data.Items[0].totalEmployees;
}
return 0;
},
scrollable: {
virtual: true
},
sortable: true,
columns: columns,
dataBound: function(arg) {
/* few more business operations */
},
scrollable: {
virtual: true
},
serverPaging: true,
serverSorting: true,
serverFiltering: true,
editable: {
'mode': 'inline',
'createAt': 'top'
},
Image showing infinite hits:
I was loading the kendo.all.js file more than once, precisely thrice. I made sure it only loads once and the issue is gone.
I am trying to get the data from a jqGrid (free version and latest version) and it's suppose that I get:
all the data if none is selected
the selected data if any
This is how I am doing it:
$(function () {
var $order_logs = $('#order_logs');
$order_logs.jqGrid({
url: Routing.generate('api_order_logs'),
datatype: "json",
colModel: $colmodel.data('values'),
width: 980,
height: 300,
pager: true,
toppager: true,
hoverrows: true,
shrinkToFit: true,
autowidth: true,
rownumbers: true,
viewrecords: true,
rowList: [25, 50, 100],
rownumWidth: 60,
gridview: true,
sortable: {
options: {
items: ">th:not(:has(#jqgh_order_logs_cb,#jqgh_order_logs_rn,#jqgh_order_logs_actions),:hidden)"
}
},
jsonReader: {
root: 'rows',
page: 'page',
total: 'total',
records: 'records',
cell: '',
repeatitems: false
},
cmTemplate: {autoResizable: true, editable: true},
autoResizing: {compact: true, resetWidthOrg: true},
autoresizeOnLoad: true
}).jqGrid('navGrid', {
edit: false,
add: false,
del: false,
search: false,
refresh: true,
refreshstate: "current",
cloneToTop: true
}).jqGrid('navButtonAdd', {
caption: 'Export',
title: 'Export',
onClickButton: function () {
var filteredData = $order_logs.jqGrid("getGridParam").lastSelectedData,
allData = $order_logs.jqGrid('getGridParam', 'data');
exportData(filteredData, allData);
}
});
});
function exportData(filteredData, allData) {
if (filteredData.length === 0 || allData.length === 0) {
alert('There is no data to export');
return;
}
// Export only the filtered data
if (filteredData.length > 0) {
return;
}
// Export all the grid data
}
For some reason the value of allData is always an empty array and I am not sure since I am using the same code as everyone is using out there and found in a lot of answer here in SO.
UPDATE:
Currently the grid is holding six columns and a set of 60 records as total paginated by 20 each time however you can change the pagination to be 50 or 100.
Can any tell me why is this?
I'd recommend to use loadonce: true, forceClientSorting: true options in case of small dataset: less at 1000 or 10000 rows. It simplifies the code server side and you can use full functionality of free jqGrid. The problem with access to lastSelectedData and data will be solved.
More then that, you can easy use many advanced features like createColumnIndex: true, generateValue: true of generateDatalist: true options and so on. See demos included in README of version 4.14.1. Good and comfortable filtering of the data is, in my option, the part of displaying the data. Having the data locally allows to find unique values and build <select> in the filter bar or to use <datalist> to have autocomplete functionality.
I am using Kendo UI's Grid system for a data grid, and am migrating my code to Typescript. I am loving it so far, but have hit a few snags; One of which is that the declaration for the grid seems to be a bit incomplete, even with Telerik's official Typescript definitions.
For example, this code works in javascript. However if I run this exact same code in Typescript, I am told that the toolbar property is invalid, because it is expecting a type of GridToolbarItem. I have traced GridToolbarItem down and, while I do find the interface for it, I cannot seem to actually declare or create it, thus I am not being allowed to create a toolbar for my grid!
elements.grid = $('#grid').kendoGrid({
dataSource: {
transport: {
read: {
url: "/administrator/data/items",
dataType: "json",
type: 'GET',
cache: false
}
},
schema: {
total: "total",
data: "data"
},
page: 0,
pageSize: 15,
take: 15,
serverPaging: true,
serverFiltering: true,
type: "aspnetmvc-ajax"
},
toolbar: kendo.template($("#search-byName").html()),
pageable: {
refresh: true,
pageSizes: true
},
selectable: "row",
columns: [
{
field: "Id",
width: 25,
title: "Identity"
},
{
field: "Name",
width: 40,
title: "Name",
template: "<div class='#: Quality.CSS #'>#: Name #</div><div>#: (Origin.Label != null) ? Origin.Label : '' #</div>"
}
],
change: function (e) {
// do some stuff when an item is selected
},
}).data("kendoGrid");
TypeScript's type system is different from that of Java or C# in that it's the shape of the type that matters, not the names in the class hierarchy. I like to think of it as a contract. The contract says you have to have certain things and it doesn't matter why you have them or if you have more.
Here's a lame example I cooked up:
interface BagOfStuff {
anum: number;
astring: string;
anany: any;
}
function processBag(bag: BagOfStuff): void { }
var aBag = {
anum: 5,
astring: "foo",
anany: {},
bonusThing: "bar"
};
processBag(aBag); // works
aBag never said it was of type BagOfStuff, but it satisfies all the requirements of one so I can pass it into processBag and that will work.
I am trying to implement server side sorting with kendo grid in my MVC application. but sorting option is not showing. i have double checked that i have enabled all the necessary option (made the serversorting to true to the the kendo grid data source and made the scrollable to true to the grid element) to do this but still i am able to find the sortable option. below is my kendo grid code
Kendo Grid Script
var grid = $("#grid");
grid.children().remove();
grid.kendoGrid({
columns: [{attributes:"",field:"",template:"${ResultFields[0].Value},title:"Column 1",width:"110px"},{attributes:"",field:"",template:"${ResultFields[1].Value},title:"Column 1",width:"110px"}],
resizable: true,
reorderable: true,
scrollable: true,
filterable: true,
columnMenu: true,
selectable: "row",
selectable: "multiple",
dataBound: function () { alert("Data Bound"); },
dataSource: {
transport: {
read: {
url: '#Url.Action("Index", "KendoServerSideSorting")',
type: "GET",
dataType: "json",
traditional: true,
data: {
itemTypeId: 1,
where: values,
orderBy: ["", "", ""],
},
},
},
schema: {
data: "Items",
total: "TotalItems",
},
serverPaging: true,
pageSize: 10,
error: function (e) {
alert(e.errors);
}
},
pageable: {
pageSize: 10,
input: true,
pageSizes: [10, 20, 30, 50, 100, 250],
},
change: function () { alert("Change event"); },
})
Controller Action will look like this
public JsonResult Search(int itemTypeId, int skip, int take, string[] where, string[] orderBy)
{
var v = Kernel.Get<IItemSearch>().Search(itemTypeId, skip, take, where, orderBy);
return Json(v, JsonRequestBehavior.AllowGet);
}
*Can anyone help me to resolve this issue. *
You can use the helper functionality from KendoGridBinderEx to parse all the commands (like filter and sort) and do the filtering and sorting at the server-side automatically using DynamicLinq.
See this project : https://github.com/StefH/KendoGridBinderEx for some examples.Also available as NuGet package : https://www.nuget.org/packages/KendoGridBinderEx/