i'm working with kendo ui to create rich user interface, but i'm stuck t the following:
I want a Grid with a subgrid, the first one displays customer info, like name, etc the second shows the available shipping-adresses, the customer saved. Now my problem is, that in the subgrid is not data, although firebug shows, that the data was returned. This is my source:
$(function() {
var main = $("#customer-grid").kendoGrid({
dataSource: {
transport:{
read :"data/users.php",
update :{
url :"data/users.php?action=update",
type:"POST",
data: function (data) {
data.birthday = kendo.toString(data.birthday, "yyyy-MM-dd");
return data;
}
},
destroy:{
url :"data/users.php?action=destroy",
type:"POST"
}
},
schema: {
data: "data",
model: {
id: "id",
fields: {
id: {editable: false},
activated: { type: "boolean" },
birthday: {type: "date"},
gender: {defaultValue: "W"}
}
}
}
},
height: 250,
filterable: true,
sortable: true,
pageable: true,
detailInit: detailInit,
dataBound: function() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
},
columns: [{
field: "id",
title: "ID",
width: "50px"
}, {
field: "gender",
title: "Geschlecht",
width: "100px",
values: data
}, {
field: "firstname",
title: "Vorname"
}, {
field: "lastname",
title: "Nachname"
}, {
field: "birthday",
title: "Geburtstag",
width: "100px",
format: "{0:dd.MM.yyyy}"
},{
field: "mail",
title: "E-Mail"
},{
field: "activated",
title: "Aktiviert",
width: "100px",
values: actval
}, {
command: ["edit", "destroy"],
title: " ",
width: "210px"
}],
editable:{
mode: "popup"
}
});
});
function detailInit(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
transport: {
read: "data/adress.php?uid="+e.data.id
},
serverPaging: true,
serverSorting: true,
serverFiltering: true,
pageSize:6
},
scrollable: false,
sortable: true,
pageable: true,
columns: [
{ field: "id", width: 70 },
{ field: "zipcode", title:"Ship Country", width: 100 },
{ field: "city", title:"Ship Address" },
{ field: "street", title: "Ship Name", width: 200 }
]
});
}
The function gets its data from a php page, which does a mysql-query and then gives back the data as application/json. But nothing is shown.
Hopefully you guys can help me.
Regards
I tested your code and it works fine.
Check:
e parameter format. I've used: detailInit({ detailCell : $("#grid"), data : { id : 1}});
JSON returned by data/adress.php. I've returned:
[
{"city":"Madrid", "id":"1", "zipcode":"31000", "street":"my street 1", "number":5},
{"city":"Sofia", "id":"2", "zipcode":"32000", "street":"my street 2", "number":4},
{"city":"London", "id":"3", "zipcode":"33000", "street":"my street 3", "number":3},
{"city":"San Francisco", "id":"4", "zipcode":"34000", "street":"my street 4", "number":2},
{"city":"Berlin", "id":"5", "zipcode":"35000", "street":"my street 5", "number":1}
]
Using the following (hardcoded) php response:
<?php
header('Content-type: application/json');
$named_array = array(
array("city" => "Madrid", "id" => "1", "zipcode" => "31000", "street" => "my street 1", "number" => 5),
array("city" => "Sofia", "id" => "2", "zipcode" => "32000", "street" => "my street 2", "number" => 4),
array("city" => "London", "id" => "3", "zipcode" => "33000", "street" => "my street 3", "number" => 3),
array("city" => "San Francisco", "id" => "4", "zipcode" => "34000", "street" => "my street 4", "number" => 2),
array("city" => "Berlin", "id" => "5", "zipcode" => "35000", "street" => "my street 5", "number" => 1)
);
echo json_encode($named_array);
?>
EDIT: This is the definition of the grid containing the subgrid.
var outer = $("#outer").kendoGrid({
dataSource:{
type:"json",
transport:{
read:"names.php"
},
pageSize:5
},
sortable:true,
columns:[
{ field:"id", width:70 },
{ field:"name", title:"Name", width:100 },
{ field:"lastname", title:"LastName", width:100 },
{ title:"Address", width:300, attributes:{ class:"ob-address"}}
]
}).data("kendoGrid");
and then on a button click, I run:
$(".ob-address", outer.tbody).each(function (idx, elem) {
detailInit({ detailCell:elem, data:{ id:1}});
});
As you can see I marked a column in the outer grid with a CSS class named ob-address and the function selects all the cell in the body of the outer table for inserting the inner table (subgrid).
Related
I have the following code:
var mdl = #Html.Raw(Json.Encode(Model.FacilityList));
var ds = new kendo.data.TreeListDataSource({
data: mdl,
schema: {
model: {
id: "ClientOrganizationId",
fields: {
parentId: { field: "ParentOrganizationId", nullable: true },
ClientOrganizationId: { field: "ClientOrganizationId", type: "number" },
Name: { field: "Name"},
Street: { field: "Street" },
City: { field: "City" },
State: { field: "State" },
ZipCode: { field: "Zipcode" }
},
expanded: true
}
}});
$("#treelist").kendoTreeList({
dataSource: ds,
selectable: true,
columns: [
{ field: "Name", title: "Organization Name"},
{ field: "Contracted", title: "Contracted"},
{ field: "ClientOrganizationId", title: "Id"},
{ field: "Street", title: "Street"},
{ field: "City", title: "City" },
{ field: "State", title: "State" },
{ field: "ZipCode", title: "ZipCode"}]});
How would I add another column that contains an actionlink to the "Home" controller's "Update" action passing the ClientOrganizationId as a parameter?
I want the Update action to be something like this
public ActionResult Update(int Id)
{
}
You use a column template; basically something like:
{
field: "ClientOrganizationId",
title: "Id link",
template: "<a href='/Home/Update/#= ClientOrganizationId #'>" +
"link me to id: #= ClientOrganizationId # </a>"
},
I.e. fill in whatever is needed to call the Update action while writing the id value with
#= ClientOrganizationId #
(I don't remember the link semantics offhand, so the href part may be very wrong)
I am displaying Grid and using detailTemplate to expandRow. But when expand the row, I want to pass the row ID and get datasource and display another grid.
I think detailTemplate won't work in this case. How can I do this ?
Here is my Code
$(document).ready(function () {
var dataSource = new kendo.data.DataSource({
pageSize: 20,
data: [
{ id: "1", name: "Andrew", age: "30" },
{ id: "2", name: "Robert", age: "29" },
{ id: "3", name: "Frank", age: "35" }
],
autoSync: true,
schema: {
model: {
id: "id",
fields: {
id: { editable: false, nullable: true, type: "number" },
name: { editable: false },
age: {
validation: { min: 0, required: true },
editable: true,
nullable: true,
type: "number"
}
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 550,
editable: "inline",
columns: [
{ field: "name",title: "Name" },
{ field: "age", title: "Age", width: "180px"},
{ command: ["edit"] }
],
detailTemplate: "<div>Name: #: name #</div><div>Age: #: age #</div>"
});
});
Did you checked this demo from Kendo UI ?
http://demos.telerik.com/kendo-ui/grid/detailtemplate
Similar to your scenario, detail grid is created in detailInit function and data for detail grid is filtered for the current employee using e.data.EmployeeID
I want to enable editing only for Address field for the below code:
$("#grid").kendoGrid({
columns: [{
field: "name",// create a column bound to the "name" field
title: "Name",// set its title to "Name"
},
{
field: "age",// create a column bound to the "age" field
title: "Age" ,// set its title to "Age"
},
{
field: "doj",
title: "DOJ",
},
{
field: "address",
title: "ADDRESS",
},
{ command: [{ name: "destroy", text: "Remove" }, { name: "edit", text: "edit" }] }],
editable: "popup",
sortable:true,
dataSource: [{ name: "Jane", age: 30, address: "Bangalore", }, { name: "John", age: 33, address: "Hyderabad" }]
});
Define editable: false & nullable: true to column of database schema.
dataSource = new kendo.data.DataSource({
..
schema: {
model: {
id: "YourID",
fields: {
YourID: { editable: false, nullable: true },
address: { editable: false, nullable: true },
..
..
}
}
}
..
})
You have to set editable: false to the columns.
model: {
fields: {
ProductID: {
editable: false
}
}
}
Does anyone know how to showing page sizes drop down list and refresh button on the footer kendo grid MVVM likes this
Here is my view code:
<div id="customer-grid"
data-role="grid"
data-sortable="true"
data-selectable="true"
data-pageable="true"
data-pagesizes="[5, 10, 20]"
data-columns='[
{ field: "CustomerID", title: "ID", width: "75px" },
{ field: "CompanyName", title: "Company"},
{ field: "ContactName", title: "Contact" },
{ field: "ContactTitle", title: "Title" },
{ field: "Address" },
{ field: "City" },
{ field: "Region" },
{ field: "PostalCode" },
{ field: "Country" },
{ field: "Phone" },
{ field: "Fax" } ]'
data-bind="source: customerSource">
</div>
and here is my data source code:
var customerSource = new kendo.data.DataSource({
transport: {
read: {
async: false,
url: crudServiceBaseUrl,
dataType: "json"
}
},
serverPaging: true,
pageSize: 10,
schema: {
model: customerModel,
data: "data",
total: "count"
},
});
Thanks in advance.
You should define data-pageable as:
data-pageable="{ refresh: true, pageSizes: [5, 10, 20] }"
Please, note that the array of page sizes is defined in data-pageable and not in data-pagesizes.
So your grid definition would be:
<div id="customer-grid"
data-role="grid"
data-sortable="true"
data-selectable="true"
data-pageable="{ refresh: true, pageSizes: [5, 10, 20] }"
data-columns='[
{ field: "CustomerID", title: "ID", width: "75px" },
{ field: "CompanyName", title: "Company"},
{ field: "ContactName", title: "Contact" },
{ field: "ContactTitle", title: "Title" },
{ field: "Address" },
{ field: "City" },
{ field: "Region" },
{ field: "PostalCode" },
{ field: "Country" },
{ field: "Phone" },
{ field: "Fax" } ]'
data-bind="source: customerSource">
</div>
Check it here : http://jsfiddle.net/9zL6J/
Not sure why my sort is not working for this gridpanel.
I set the sorters property, I believe correctly.
And I set the sortOnLoad property as well.
Not sure why this simple case is not working.
I don't think I need to do a remote sort in this case, so just not sure why this is not working.
Ext.onReady(function() {
Ext.define('com.myCompany.MyGridModel', {
extend : 'Ext.data.Model',
fields : [{
name : 'name',
type : 'string'
}, {
name : 'address',
type : 'string'
}, {
name : 'type',
type : 'string'
}]
});
var store = Ext.create('Ext.data.Store', {
model: 'com.myCompany.MyGridModel',
proxy: {
type: 'ajax',
url: 'centers.json',
reader: {
type: 'json',
root: 'centers'
},
sortOnLoad: true,
sorters: { property: 'name', direction : 'ASC' }
}
});
store.load();
var grid = Ext.create('Ext.grid.Panel', {
layout: 'fit',
store: store,
columns: [{
text: 'Name',
dataIndex: 'name',
name: 'name'
}, {
text: 'IP Address',
dataIndex: 'address',
name: 'address'
}, {
text: 'Type',
dataIndex: 'type',
name: 'type'
}],
renderTo: Ext.getBody(),
});
grid.getView().refresh();
});
{
"centers": [
{
"name": "South Test Center",
"address": "30.40.50.60",
"type": "TestType2"
},
{
"name": "East Test Center",
"address": "50.60.70.80",
"type": "TestType1"
},
{
"name": "West Test Center",
"address": "40.50.60.70",
"type": "TestType3"
},
{
"name": "North Test Center",
"address": "20.30.40.50",
"type": "TestType4"
}
]
}
The sortOnLoad and sorters configuration options should be placed directly on the store, not on the model.
See the Ext.data.Store documentation here:
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-cfg-sorters
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.data.Store-cfg-sortOnLoad