KendoUI TreeView binding issue - kendo-ui

I am facing an issue , below code bind the tree for first time , but not working binding the tree on second time :( but when i request third its bind again.
Means even request work .
please help me
Thanks in advance
Mobeen
// My Example Data
{"d":[{"_type":"ManageUPPRM.UserDocumentDTO","DocumentID":1804105651,"DocumentName":"Google Talk","hasChildren":true},{"_type":"ManageUPPRM.UserDocumentDTO","DocumentID":15854591701,"DocumentName":"desktop.ini","hasChildren":false},{"__type":"ManageUPPRM.UserDocumentDTO","DocumentID":15861429553,"DocumentName":"Jellyfish.jpg","hasChildren":false}]}
//Code
var datasource = new kendo.data.HierarchicalDataSource({
transport: {
read: function (options) {
var id = options.data.DocumentID;
if (typeof id == "undefined") {
id = "0"
}
$.ajax({
type: "POST",
url: "../ManageUPWebService.asmx/GetAllDocuments",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: "{DocumentID:'" + id + "'}",
success: function (result) {
// notify the data source that the request succeeded
options.success(result.d);
},
error: function (result) {
// notify the data source that the request failed
options.error(result.d);
}
});
}
},
schema: {
model: {
id: "DocumentID",
text: "DocumentName",
hasChildren: "hasChildren"
}
}
});
$("#treeview").kendoTreeView({
checkboxes: {
checkChildren: true,
template: "<input type='checkbox' name='#=item.id#' data-text='#=item.DocumentName#' value='true' />"
},
loadOnDemand: true,
dataSource: datasource,
dataTextField: "DocumentName"
});

try this,
add a div with some id as the parent div of treeview
<div id="parent"><div id="treeview"></div></div>
and before binding the kendo tree
$("#treeview").remove();
$("<div id=\"treeview\" />").appendTo("#parent").kendoTreeView({
checkboxes: {
checkChildren: true,
template: "<input type='checkbox' name='#=item.id#' data-text='#=item.DocumentName#' value='true' />"
},
loadOnDemand: true,
dataSource: datasource,
dataTextField: "DocumentName"
});

Related

kendo Grid custom edit send [object Object]

I want implement kendo Grid custom editor (dropdownlist).
everythin is ok but if create new record or update exists record when dropdown column is null I got error in updating, in debugging I saw
'[object Object]' sent as value of continent column ,
but when dropdown column has value I can change dropdown value and update record is OK!!!
my code is:
var crudServiceBaseUrl = "http://localhost:8090/hr";
var countryDataSource =
new kendo.data.DataSource({
transport: {
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {
models: kendo.stringify(options.models)
};
}
},
read: {
url: crudServiceBaseUrl + "/countries",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/countries/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/countries/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/countries/Create",
dataType: "jsonp"
}
},
schema : {
data : "items"
},
model: {id : "CD_CONT",
fields: {
CD_CONT : { type: "string",editable : false},
NAME_CONT : { type: "string",editable : true,nullable : false},
CONTINENT : { type: "string",editable : true,nullable : true}
}
}
});
var continentDataSource = new kendo.data.DataSource({
data: [ { continent:"1",name:"asia"},
{ continent:"2",name:"europ"},
{ continent:"3",name:"america"}
]
});
$('#grid).kendoGrid({
toolbar: ["create","save", "cancel",],
columns: [
{
field: "CD_CONT" ,
title: "Cd cont"
},
{
field: "NAME_CONT" ,
title: "Name cont"
},
{
field: "CONTINENT" ,
title: "Continent",
editor: function ContinentDropDown(container, options) {
$('<input data-text-field="name" data-value-field="continent" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataSource: continentDataSource,
dataTextField: "name",
dataValueField: "continent"
});
}
}
],
dataSource: countryDataSource ,
editable: "inline"
});
also how to set field template to show textValue of Continent in grid?
Did you forget to add the name in your editor?
$('<input data-text-field="name" data-value-field="continent" data-bind="value:' + options.field + '" name='" + options.field + "'/>')

Why is Kendo dropDownList undefined

I want to populate a Kendo dropdownlist with data from a database.
That's what I call the "frwMantenimientoEmpresas.aspx / SelectProvincias" method.
My problem is that the value "undefined" after making the call, in the dropdownlist appears ...
dataSource1 = new kendo.data.DataSource({
serverFiltering: true,
transport: {
read: {
beforeSend: function (req) {
//alert("");
},
async: false,
url: "frwMantenimientoEmpresas.aspx/SelectProvincias",
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8"
}
},
schema: {
model: {
fields: {
UIDProvincia: { type: "int" },
Nombre: { type: "string" }
}
}
}
});
$("#dropProv").kendoDropDownList({
dataSource:dataSource1,
dataTextField: "Nombre",
dataValueField: "UIDProvincia",
autoBind: true,
});
The read method calls the server SelectProvincias method correctly..
At this point dropDownList = undefined??

How to find selected ListView Item in Kendo UI DataASource Destroy

I have a KendoUI DataSource
var myDS = new kendo.data.DataSource({
transport: {
read:
{
url: getData,
contentType: 'application/json; charset=utf-8',
},
destroy:
{
url: deleteData,
contentType: 'application/json; charset=utf-8',
},
parameterMap: function(options, operation) {
if (operation !== "destroy" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "Id",
fields: {
Id: { editable: false, nullable: true },
name: { type: "string" }
}
}
}
});
I am binding data source to Kendo ListView as follows
var listView = $("#alistview").kendoListView({
dataSource: myDS ,
template: kendo.template($("#template").html())
}).data("kendoListView");;
I have created ListView and widget as follows,
<div id="alistview" style="margin-top:30px"></div>
<script type="text/x-kendo-tmpl" id="template">
<div>
<div>
#:name#
<a class="k-button k-button-icontext k-delete-button" href="\\#"><span class="k-icon k-delete"></span></a>
</div>
</div>
</script>
</div>
On the delete button click the destroy object of KendoUI DataSource is getting called. My question is how to fetch selected item of the ListView in the destroy object of the datasource. For example I want to read name of the selected item when user click on the delete button.
any help ?
I got the answer. We can use function in the url instead of the object and inside the function selected item which is calling the destroy can be fetched as follows:
var myDS= new kendo.data.DataSource({
transport: {
read:
{
url: getdata,
contentType: 'application/json; charset=utf-8',
},
destroy:
{
url: function (appt) { return deteletedata+ "?accountid=" + appt.Id },
contentType: 'application/json; charset=utf-8',
//data: {
// AccountId: "3"
//}
},
parameterMap: function(options, operation) {
if (operation !== "destroy" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
schema: {
model: {
id: "Id",
fields: {
Id: { editable: false, nullable: true },
accountname: { type: "string" }
}
}
}
});

kendo ui grid dropdownlist cannot pass its value while adding a new record

The below case refers to:http://demos.telerik.com/kendo-ui/grid/editing-custom
The adding screen works, but the add failed because of the dropdownlist cannot get value.
The problem is: when add a new record, and then select a Curve Term (not the default value), the dropdown cannot get any value, that is, the json backend is: "curvetermid":""
The code is as below:
<div id="grid"/>
var dataSource = new kendo.data.DataSource ({
batch:true,
transport:{
read: function (options) {
$.ajax({
type: "POST",
url:"",
data:"/idx/list",
dataType:"json",
contentType: "application/json; charset=utf-8",
success: function(result) {
options.success(result);
}
})
},
create: function(options) {
$.ajax({
type: "POST"
,url:"/create"
,dataType:"json"
,contentType: "application/json; charset=utf-8"
,data:kendo.stringify(options.data.models)
,success:function(result) {
options.success(result);
}
});
},
parameterMap:function(options,operation) {
return kendo.stringify(options.models);
}
},
schema:{
data: result.data,
total:result.total,
model:{
id:idKey,
fields:{
idKey: {type:"number"},
**curveterm: {validation: {required: true}}**
}
}
}
});
$("#grid").kendoGrid({
dataSource:dataSource,
columns: [
{field: "idKey", title: "ID"},
**{field: "curvetermid",
title: "Curve Term",
editor: fnDdlCurvetermEditor,
template: "#=curveterm.curvetermname#"}
]**,
editable:{mode:"popup", confirmation:"Are you sure you want to remove this item?"}
});
function fnDdlCurvetermEditor(container,options) {
var data = [{"curvetermid":0,"curvetermname":"NA","isactive":1}, {"curvetermid":1,"curvetermname":"AAA","isactive":1},{"curvetermid":2,"curvetermname":"BBB","isactive":1}];
var ddlVar = $('<input id="curvetermid" name="curvetermid" '
+ ' data-value-field="curvetermid" '
+ ' data-text-field="curvetermname"'
+ ' data-bind="value: ' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataTextField: "curvetermid",
dataValueField: "curvetermname",
dataSource: data
});
}

Kendo Grid groupping

I read this topic and use open source edition of kendo web, my current version is Kendo UI Web v2012.3.1114. My problem is exist as the link above and I could not solve it.
Part of my script is here:
function load() {
var grid = $("#grid").data("kendoGrid");
if (grid) {
//destroy the previous Grid instance
grid.destroy();
//clean up the html
grid.wrapper.html("");
}
var crudServiceBaseUrl = "WebForm.aspx",
//datasource = null;
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "?q=load&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "?q=update&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "?q=destroy&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "?q=create&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: getmodel()
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
//pageable: true,
selectable: true,
//groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true
},
height: 500,
toolbar: ["create", "save", "cancel"],
columns: getColumns(),
editable: true
});
}
Every thing is ok, but only after loading page I can only One time group by headers.
It seems that this behavior is improved in the latest version of KendoUI 2012 Q3 SP1 (v.2012.3.1315), where the grouping is working as expected. For convenience I created this sample.

Resources