How do I get the ID of a node in a Kendo treeview from a remote JSON and put it as a variable to use in a grid's remote datasource url as parameter?
Here is the code for tree:
... and here is the code for grid:
Any help will be apreciated. Thanks!
Here is the code for tree:
<script id=
"treeview-template"
type=
"text/kendo-ui-template"
>
#: item.Name #
</script>
<script>
var
meterid = 1179;
var
treeurl =
'treeview_remote_url'
;
var
datatree =
new
kendo.data.HierarchicalDataSource({
transport: {
read: {
url: treeurl,
dataType:
"json"
,
cache:
true
}
},
schema:
{
model:
{
children:
"Children"
,
fields:
{
id: { type:
"number"
},
Name: { type:
"string"
}
}
}
}
});
function
onSelect(e) {
var
treeview = $(
"#treeview"
).kendoTreeView({
select:
function
() {
meterid = ($(
this
).text());
}
});
$(
"#grid"
).data(
"kendoGrid"
).dataSource.read();
}
$(document).ready(
function
() {
$(
"#treeview"
).kendoTreeView(
{
template: kendo.template($(
"#treeview-template"
).html()),
dataSource: datatree,
dataTextField:
"id"
});
var
treeview = $(
"#treeview"
),
kendoTreeView = treeview.data(
"kendoTreeView"
);
treeview.on(
"click"
,
".k-in"
,
function
(e) {
kendoTreeView.toggle($(e.target).closest(
".k-item"
));
onSelect();
});
});
... and here is the code for grid:
<script>
var
dateRegExp = /^\/Date\((.*?)\)\/$/;
function
toDate(value) {
var
date = dateRegExp.exec(value);
return
new
Date(parseInt(date[1]));
}
sourceUrl =
"grid_remote_url... &id="
+ meterid;
$(document).ready(
function
() {
$(
"#grid"
).kendoGrid({
dataSource: {
type:
"json"
,
transport: {
read: sourceUrl
},
refresh:
true
,
serverSorting:
true
,
scrollable:
true
},
height:
'100%'
,
scrollable: {
virtual:
false
},
columns: [
{ field:
"data"
, title:
"Date/Time"
, template:
'#= kendo.toString(toDate(data), "dd/MM/yyyy HH:ss")#'
, width:
'10%'
},
{ field:
"valoare"
, title:
"Energy (MWh)"
, template:
'#= kendo.toString(valoare, "n5")#'
},
{ field:
"valoare"
, title:
"Energy (MWh)"
, template:
'#= kendo.toString(valoare, "n5")#'
}
]
});
});
</script>
Any help will be apreciated. Thanks!