How to control the Kendo Grid? - asp.net-mvc-4

How do I control how many rows appear in a kendo grid? Real Estate is limited, so I need to have a lot of info in a pretty compact space. I'm trying to pack everything in my grid in a 300-pixel high area.
The issue I'm having is that all 200-plus rows of data that are being returned from my MVC JsonResult in my controller are displaying at once, on a single page. Not quite exactly what I'm looking for.
Code is below, if someone a little more knowledgeable about formatting a kendo grid could help out, I'd appreciate it.
Thanks!
-RC
{}
var RemoteJsonData_Call = new kendo.data.DataSource({
transport:
{
read: {
type: "GET",
dataType: "json",
url: resourceURL_Call
},
pageSizes: 8,
serverPaging: true
},
schema: {
model: {
ScheduleData: {
extensionDataField: {
fields: {
ScheduleDate: { type: "date" },
ScheduleAmount: { type: "number" },
SchedulePrice: { type: "number" },
ScheduleNotes: { type: "string" }
}
}
}
}
}
})
$('#callSched').kendoGrid({
height: '300',
sortable: true,
reorderable: true,
resizable: true,
pageable: {
numeric: true,
refresh: true,
pageSizes: true,
previousNext: true,
input: true,
info: true
},
columns: [
{
field: "ScheduleDate",
title: "Date",
template: "#= kendo.toString(kendo.parseDate(ScheduleDate, 'MM-dd-yyyy'), 'MM-dd-yyyy') #"
},
{
field: "ScheduleAmount",
title: "Amount",
},
{
field: "SchedulePrice",
title: "Price"
},
{
field: "ScheduleNotes",
title: "Notes"
}
], dataSource: RemoteJsonData_Call
});
{}

The problem is that you have defined that the paging is done in the server when it is not. You should say:
serverPaging: false
or just nothing since the default value is false.
With this you should have a grid with the number of pixels specified in the height option (in your example 300 pixels). Other options in you example are correct.

You have server paging and page size set up incorrectly here:
var RemoteJsonData_Call = new kendo.data.DataSource({
transport:
{
read: {
type: "GET",
dataType: "json",
url: resourceURL_Call
},
pageSizes: 8,
serverPaging: true
},
It should be:
var RemoteJsonData_Call = new kendo.data.DataSource({
transport:
{
read: {
type: "GET",
dataType: "json",
url: resourceURL_Call
}
},
pageSize: 8,
serverPaging: true
The config options were in the wrong place, and "pageSizes" was misspelled, it should be "pageSize" with no "s" on the end.
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-pageSize

Related

jqgrid paging issue - Not loaded data with page

I am using Jqgrid with customized Edit, Delete buttons. Also , I am using external search to search in grid. I am fustrating with one problem since two days.
Please check my code below of binding jqgrid
jQuery(document).ready(function () {
var myGrid = $('#list');
myGrid.jqGrid({
url: '/Site/GetData/',
datatype: "json",
contentType: "application/json; charset-utf-8",
mtype: 'POST',
loadonce: true,
colNames: ['Site ID', 'Site Name', 'Email Address', 'Website', 'Contact Person', 'Phone number', 'Mobile number', "Edit", "Delete"],
colModel:
[
{ name: 'SiteID', hidden: true },
{ name: 'SiteName' },
{ name: 'EmailID' },
{ name: 'Website' },
{ name: 'ContactPerson' },
{ name: 'PhoneNo' },
{ name: 'MobileNo' },
{ name: 'Edit', width: 50, sortable: false, formatter: ColumnFormatter },
{ name: 'Delete', width: 60, sortable: false, formatter: ColumnFormatter },
],
autowidth: true,
rowNum: 5,
rowList: [5, 10, 20, 50],
pager: jQuery('#pager'),
sortorder: "desc",
viewrecords: true,
gridview: true,
ignoreCase: true,
}).navGrid('#pager',
{
rowNum: 5, edit: false, add: false, del: false, search: false, refresh: true
}
);
});
Using Above code I am binding Jqgrid.
Now, I need to delete a row from the grid, after deleting I need to refresh whole the grid. But it does not kept data according to page. Please check my delete function below :
function deleteRow(imageElement, UserId) {
var data = new Object();
data.id = UserId;
var _data = JSON.stringify(data);
$("#list").setGridParam({ datatype: 'json' });
$.ajax({
url: '#Url.Action("Delete", "Site")',
type: "POST",
contentType: "application/json; charset=utf-8",
data: _data,
success: function (result) {
var currentPage = $('#gridData').getGridParam('page');
$('#list').trigger('reloadGrid');
$("#list").setGridParam({ page: currentPage })
},
error: function (result) {
alert("This data can not be deleted");
}
});
}
Okay , using above code , I am deleting row, and if response is Success than need to reload whole the grid.
Now if I am at 2nd page and deleting any row, than it will reloads the grid , it shows me Page number is set as 2. But records shows me from 1st page of grid.
Please help me for that
I' m not sure that I correctly understand the behavior which you need to implement. If you want to reload the whole grid from the server then you should reset the value of datatype before reloading. The reason: you use loadonce: true which loads the data from the server once, save it in internal jqGrid parameters data and _index and then the datatype will be changed to "local". So if you want to reload the data from the server you should execute
$('#list').jqGrid('setGridParam', {datatype: 'json'});
before reloadGrid.
Additionally if you need to reload grid with specific page you can use page parameter of jqGrid (see the answer for details). In the most cases the usage of current:true option is what one need. So the code should be something like below
...
success: function (result) {
$("#list").setGridParam({ datatype: 'json' })
.trigger('reloadGrid', [{ current: true }]);
}

Kendo UI BarChart Data Grouping

Not sure if this is possible. In my example I am using json as the source but this could be any size. In my example on fiddle I would use this data in a shared fashion by only binding two columns ProductFamily (xAxis) and Value (yAxis) but I would like to be able to group the columns by using an aggregate.
In this example without the grouping it shows multiple columns for FamilyA. Can this be grouped into ONE column and the values aggregated regardless of the amount of data?
So the result will show one column for FamilyA of Value 4850 + 4860 = 9710 etc.?
A problem with all examples online is that there is always the correct amount of data for each category. Not sure if this makes sense?
http://jsfiddle.net/jqIndy/ZPUr4/3/
//Sample data (see fiddle for complete sample)
[{
"Client":"",
"Date":"2011-06-01",
"ProductNumber":"5K190",
"ProductName":"CABLE USB",
"ProductFamily":"FamilyC",
"Status":"OPEN",
"Units":5000,
"Value":5150.0,
"ShippedToDestination":"CHINA"
}]
var productDataSource = new kendo.data.DataSource({
data: dr,
//group: {
// field: "ProductFamily",
//},
sort: {
field: "ProductFamily",
dir: "asc"
},
//aggregate: [
// { field: "Value", aggregate: "sum" }
//],
//schema: {
// model: {
// fields: {
// ProductFamily: { type: "string" },
// Value: { type: "number" },
// }
// }
//}
})
$("#product-family-chart").kendoChart({
dataSource: productDataSource,
//autoBind: false,
title: {
text: "Product Family (past 12 months)"
},
seriesDefaults: {
overlay: {
gradient: "none"
},
markers: {
visible: false
},
majorTickSize: 0,
opacity: .8
},
series: [{
type: "column",
field: "Value"
}],
valueAxis: {
line: {
visible: false
},
labels: {
format: "${0}",
skip: 2,
step: 2,
color: "#727f8e"
}
},
categoryAxis: {
field: "ProductFamily"
},
legend: {
visible: false
},
tooltip: {
visible: true,
format: "Value: ${0:N0}"
}
});​
The Kendo UI Chart does not support binding to group aggregates. At least not yet.
My suggestion is to:
Move the aggregate definition, so it's calculated per group:
group: {
field: "ProductFamily",
aggregates: [ {
field: "Value",
aggregate: "sum"
}]
}
Extract the aggregated values in the change handler:
var view = products.view();
var families = $.map(view, function(v) {
return v.value;
});
var values = $.map(view, function(v) {
return v.aggregates.Value.sum;
});
Bind the groups and categories manually:
series: [ {
type: "column",
data: values
}],
categoryAxis: {
categories: families
}
Working demo can be found here: http://jsbin.com/ofuduy/5/edit
I hope this helps.

Sencha Touch 2.0 List Paging plugin working on one list, but not another

I have two lists in 2 separate tabs, both hooked up to a server side database. I'm attempting to set up list paging and on one of the lists its functioning exactly as it should be. For the other list, the model and store have all the same settings as the list that pages properly but no 'Load More..." text shows up at the bottom for this list.
With regards to the list paging plugin, both lists are basically exactly the same as each other (ie the Store, Model, 'List' view) but on one the paging just does not work. Does anyone have any idea what could possibly be causing this?
Editing with some more information:
I'm using Chrome to develop. Looking at the Network I seem to be getting JSON that looks right, for the one thats not working it's returning 8 records, and the total property returned is 13 (this makes sense because I've got my page size set to 8).
The Store from list that does NOT work
Ext.define("IdeaBank.store.SharedProblems", {
extend: "Ext.data.Store",
required: "IdeaBank.model.SharedProblem",
config: {
model: "IdeaBank.model.SharedProblem",
clearOnPageLoad: false,
pageSize: 8,
proxy: {
type: 'ajax',
api: {
create: "http://mywebsite.com/submitProblem.php?action=create",
read: "http://mywebsite.com/submitProblem.php?action=read",
update: "http://mywebsite.com/submitProblem.php?action=update",
destroy: "http://mywebsite.com/submitProblem.php?action=delete",
},
reader: {
type: 'json',
rootProperty: "problems",
totalProperty: "total",
}
},
autoLoad: true
}
});
The Store from list that does work
Ext.define("IdeaBank.store.SharedSolutions", {
extend: "Ext.data.Store",
required: "IdeaBank.model.SharedSolution",
config: {
model: "IdeaBank.model.SharedSolution",
clearOnPageLoad: false,
proxy: {
type: 'ajax',
api: {
create: "http://mywebsite.com/submitSolution.php?action=create",
read: "http://mywebsite.com/submitSolution.php?action=read",
update: "http://mywebsite.com/submitSolution.php?action=update",
destroy: "http://mywebsite.com/submitSolution.php?action=delete",
},
reader: {
type: 'json',
rootProperty: "solutions",
totalProperty: "total",
}
},
pageSize: 8,
autoLoad: true
}
});
List view from the one that does NOT work
Ext.define("IdeaBank.view.SharedProblemsList", {
extend: 'Ext.dataview.List',
alias: 'widget.sharedproblemslist',
requires: ['Ext.plugin.ListPaging'],
config: {
autoLoad: true,
plugins: [
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: true
}
],
loadingText: "Loading...",
emptyText: [
"</pre><div class='notes-list-empty-text' style = 'padding: 2em;'>",
"<p>There are no problems listed for the category you have selected.</p>",
"</div><pre>"
].join(""),
onItemDisclosure: true,
itemTpl: [
"</pre>",
"<div class = 'list-item-title'><span style = 'margin-right: 5px; color: #25E014; font-size: 0.7em;'>{rating}</span> {problem}</div>",
"<pre>"
].join(""),
}
});
List view from the one that does work
Ext.define("IdeaBank.view.SharedSolutionsList", {
extend: 'Ext.dataview.List',
alias: 'widget.sharedsolutionslist',
requires: ['Ext.plugin.ListPaging'],
config: {
autoLoad: true,
plugins: [
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: true
}
],
loadingText: "Loading...",
emptyText: [
"</pre><div class='notes-list-empty-text' style = 'padding: 2em;'>",
"<p>There are no published solutions for the category you have selected.<p>",
"</div><pre>"
].join(""),
onItemDisclosure: true,
itemTpl: [
"</pre>",
"<div class = 'list-item-title'><span style = 'margin-right: 5px; color: #25E014; font-size: 0.7em;'>{rating}</span> {title}</div>",
"<pre>"
].join(""),
}
});
Make sure that you implement the paging logic in your server side codes. You have to supply the functionality of sending page by page. Maybe "submitSolution.php" does not send the data partially.

Extjs 4 treepanel bug

I use a simple treepanel for my application, and sometimes it stops expanding and unexpanding nodes with the next error:
records[i] is undefined
http://localhost:8080/extjs/ext-all-debug.js
Line 58763
My code is quite simple:
var tree_store = Ext.create('Ext.data.TreeStore', {
id: 'tree_store_id',
proxy: {
type: 'ajax',
url: 'tree_data.json?object_id=' + Ext.getCmp('object_id').value
},
root: {
text: 'Парки',
id: 'objectId',
expanded: true,
iconCls: 'tree-cls-root'
}
});
var tree = Ext.create('Ext.tree.Panel', {
id: 'stock_tree_id',
store: tree_store,
autoWidth: true,
height: 600,
autoScroll: true,
renderTo: document.getElementById('stock_tree_div'),
useArrows: true,
border: false,
rootVisible: true,
listeners: {
itemclick: function (view, rec, item, index, eventObj) {
document.getElementById("stock_div").innerHTML = rec.data.text;
}
}
});
Has anyone faced this problem?
May be it's problem at your JSON. Is it include something like:
"leaf" : "true",
"expanded" : "true"
?
In my case this was caused by the fact that server response json contained parent node as a first element.
So when I was expanding node 123, server was returning node 123 itself and then all of it's children.

Extjs Combobox Autocomplete

I am using Extjs 4 ComboBox with remote mode. but when i typed any character data is not filtered. and even focus is changed only for first 12 value.
I am new to Extjs 4. Please help me how to do this.
my code is:
Ext.define('MyGroup.combo', {
extend: 'Ext.form.ComboBox',
alias: 'widget.mycombo',
emptyText:'select keyword',
store: keywordStore,
valueField:'name',
displayField:'name',
mode: 'remote',
autoSelect: false,
selectOnFocus:true,
//shadow:true,
//forceSelection: false,
//triggerAction: 'all',
hideTrigger:true,
//multiSelect:true,
typeAhead:true,
minChars:1
});
Ext.define('keywordModel', {
extend: 'Ext.data.Model',
proxy: {
type: 'ajax',
url : '/keywordServlet',
method:'POST',
reader: {
type: 'json',
root: 'rows'
//,totalProperty: 'totalCount'
}
},
fields: [
{name: 'name', mapping: 'name'}
]
});
var keywordStore = Ext.create('Ext.data.Store', {
// pageSize: 10,
model: 'keywordModel'
});
As per my knowledge i think this will be helpful for you:
Ext.define('MyGroup.combo', {
extend: 'Ext.form.ComboBox',
alias: 'widget.mycombo',
initComponent: function() {
this.callParent([arguments]);
}
});
var keywordStore = Ext.create('Ext.data.SimpleStore',{
fields: ['id', 'name'],
data: [[1, 'mr'],[2, 'mr(yes)'],[3, 'mr(no)'], [4, 'example'], [5, 'example(yes)'],[6,'example(no)'],[7,'sample'],[8,'sample(yes)'],[9,'sample(no)'],[10,'mrs'],[11,'mrs(yes)'],[12,'mrs(no)']]
});
Ext.widget('mycombo',{
xtype : 'combo',
emptyText:'select keyword',
store: keywordStore,
valueField:'name',
displayField:'name',
mode: 'remote',
autoSelect: false,
selectOnFocus:true,
//shadow:true,
//forceSelection: false,
//triggerAction: 'all',
hideTrigger:true,
//multiSelect:true,
typeAhead:true,
minChars:1,
renderTo :document.body
});
And one more thing is no one is trying to answer each and every question,but every one is trying to help some body like us:-)