or
myViewModel.ScaleOptions().max = newValue;
myViewModel.ScaleOptions({
min: 0,
max: newValue,
ranges: [{
from: 0,
to: 40
}, {
from: 40,
to: 80
}, {
from: 80,
to: newValue
}]
});
I was wondering if any one had a working example of loading data onto a grid using a Java action?
The following is a code snippet of something I did a while back using DHTMLX Grid and Dojo.
So, inside my JSP I call the Java action that returns the data in XML format like so:
<
script
>
var mysubgrid;
mysubgrid = new dhtmlXGridObject('gridbox');
function doInitSubGrid(rowID)
{
var leadsSourceRecId = rowID ;
var URL = "" ;
var query = "pLeadsSourceRecId=" + leadsSourceRecId ;
mysubgrid = new dhtmlXGridObject('mysubgrid_container');
mysubgrid.setImagePath("../dhx/codebase/imgs/");
mysubgrid.setHeader("LEADS MASTER LIST,#cspan,#cspan,#cspan,#cspan,#cspan") ;
mysubgrid.attachHeader("Status, Source, Date, Name, Email, Home Phone");
mysubgrid.attachHeader("#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter");
mysubgrid.setInitWidths("80,100,100,170,170,100");
//mysubgrid.setColAlign("left,left,left,left,left,left")
mysubgrid.setSkin("light");
mysubgrid.setColSorting("str,str,str,str,str,str");
mysubgrid.setColTypes("ro,ro,ro,ro,ro,ro");
mysubgrid.attachEvent("onRowSelect",doOnRowSelectedSubGrid);
mysubgrid.init();
// HERE IS WHERE I CALL MY JAVA ACTION: GetLeadsGridDataStr.action
// I PASS A PARAMETER CALLED pLeadsSourceId
mysubgrid.loadXML("GetLeadsGridDataStr.action?pLeadsSourceRecId=" + leadsSourceRecId) ;
}
</
script
>
Does Anybody have an example like this one using Kendo?
<
select
name
=
"weekChooser"
onchange
=
"javascript:handleSelect(this);"
>
<
option
id
=
"choose0"
value
=
"#chartView?period=13"
>CW13 - 26/03/2012</
option
>
<
option
id
=
"choose1"
value
=
"#chartView?period=14"
>CW14 - 02/04/2012</
option
>
</
select
>
<
script
type
=
"text/javascript"
>
function handleSelect(elm)
{
window.location = elm.value;
}
</
script
>
<
div
data-role
=
"view"
id
=
"chartView"
data-title
=
"Some Title"
data-layout
=
"databinding"
data-init
=
"initChart"
data-show
=
"refreshChart"
>
<
div
>
</
div
>
</
div
>
@{
ViewBag.Title = "Grid";
}
@section scripts {
<
script
type
=
"text/javascript"
>
var wnd;
var myModel = kendo.data.Model.define({
id: "PrimaryKey",
fields: {
PrimaryKey: { type: "number", editable: false, nullable: false },
FirstField: { type: "string" },
SecondField: { type: "string" }
}
});
var myDataSource = new kendo.data.DataSource({
type: "json",
transport: {
read: {
url: "@Url.Action("List")",
contentType: "application/json; charset=utf-8",
type: "POST"
},
create: {
url: "@Url.Action("Create")",
contentType: "application/json; charset=utf-8",
type: "POST"
},
update: {
url: "@Url.Action("Update")",
contentType: "application/json; charset=utf-8",
type: "POST"
},
destroy: {
url: "@Url.Action("Delete")",
contentType: "application/json; charset=utf-8",
type: "POST"
},
parameterMap: function (data, type) {
if (type == "read") {
if (data.filter) {
data = $.extend({ sort: null, filter: data.filter.filters[0] }, data);
} else {
data = $.extend({ sort: null, filter: null }, data);
}
return JSON.stringify(data);
} else {
return JSON.stringify({ model: data });
}
}
},
batch: false,
pageSize: 3,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
schema: {
errors: function (response) {
if (response.Errors) {
alert(response.Errors);
myDataSource.cancelChanges();
}
},
aggregates: function (response) {
response.Aggregates;
},
data: function (response) {
return response.Data;
},
total: function (response) {
return response.TotalRecordCount;
},
model: myModel
}
});
$(document).ready(function () {
isCreating = false;
$("#grid").kendoGrid({
dataSource: myDataSource,
height: 250,
selectable: true,
pageable: true,
toolbar: [
{ name: "create", text: "New item" }
],
columns: [
{
field: "PrimaryKey",
title: "Primary Key",
attributes: {
style: "text-align: center"
},
width: 100
},
{
field: "FirstField",
title: "First Field",
attributes: {
style: "text-align: center"
}
},
{
field: "SecondField",
title: "Second Field",
attributes: {
style: "text-align: center"
},
width: 180
},
{
command: [
{
name: "edit",
text: { // sets the text of the "Edit", "Update" and "Cancel" buttons
edit: "Edit me",
update: "Save",
cancel: "I give up"
}
},
{ text: "Delete", click: ShowConfirmation }
],
// sets the title and the width of the commands column
title: " ",
width: "180px"
}
],
editable: {
mode: "popup",
update: true
},
edit: function (e) {
if (isCreating) {
e.container.kendoWindow("title", "New item");
isCreating = false;
} else {
e.container.kendoWindow("title", "Item updated");
}
}
});
wnd = $("#confirmationBox")
.kendoWindow({
title: "Brisanje stavke",
animation: false,
modal: true,
width: "370px"
}).data("kendoWindow");
$(".k-grid-add").on("click", function () {
isCreating = true;
});
$("#confirmationOKButton").click(function (e) {
DoAjaxDelete();
return false;
});
$("#confirmationCancelButton").click(function (e) {
wnd.close();
return false;
});
});
function ShowConfirmation(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
wnd.center().open();
$("#deleteID").val(dataItem.SIzborID);
}
function DoAjaxDelete() {
$.ajax({
type: "POST",
url: "@Url.Action("Delete")",
data: $("#deletePopup").serialize(),
success: function (response) {
if (response == "OK") {
//osvježimo grid
var first = myDataSource.get($("#deleteID").val());
myDataSource.remove(first);
myDataSource.sync();
//zatvorimo popup
wnd.close();
}
else {
alert('Delete failed for the following reason: ' + response);
}
}
});
}
</
script
>
}
<
h2
>Grid</
h2
>
<
p
> </
p
>
<
div
id
=
"grid"
></
div
>
<
div
id
=
"confirmationBox"
style
=
"display:none"
>
<
form
id
=
"deletePopup"
>
<
input
type
=
"hidden"
id
=
"deleteID"
name
=
"deleteID"
/>
<
p
class
=
"confirmationQuestion"
style
=
"padding:10px 0"
><
span
class
=
"exclamationIcon"
style
=
"float:left; margin:0 7px 20px 0;"
></
span
>Are you sure you want to delete this?</
p
>
<
a
class
=
"k-button"
id
=
"confirmationOKButton"
>Sure</
a
>
<
a
class
=
"k-button"
id
=
"confirmationCancelButton"
>Get me out of here</
a
>
</
form
>
</
div
>
getter:
function
(expression, safe) {
return
getterCache[expression] = getterCache[expression] ||
new
Function(
"d"
,
"return "
+ kendo.expr(expression, safe));
},