or
@{
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));
},
<table id=
"Table1"
style=
"height: 450px"
>
<thead>
<tr>
<th data-field=
"surName"
>Surname</th>
<th data-field=
"foreName"
>Forename</th>
<th data-field=
"dOB"
>DoB</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smith</td><td>John</td><td>21/5/2001</td>
</tr>
</tbody>
</table>
<script type=
"text/javascript"
>
var
s =
new
GetPats();
var
result = s.getpatlist(
'Benz'
);
//Data source
var
localDataSource =
new
kendo.data.DataSource({ data: result, pagesize: 10, page:1 });
$(
"#Table1"
).kendoGrid({
columns: [{ field:
"surName"
, title:
"Surname"
}, { field:
"foreName"
, title:
"Forename"
}, { field:
"dOB"
, title:
"Date of Birth"
, template:
'#= kendo.toString(dOB,"dd MMMM yyyy") #'
}],
dataSource: localDataSource,
groupable:
true
,
scrollable:
false
,
sortable:
true
,
pageable:
true
,
height: 450,
selectable:
true
});
</script>
<
ul
data-role
=
"listview"
data-style
=
"inset"
data-type
=
"group"
>
<
li
>
<
ul
>
<
li
>Bob Jones</
li
>
</
ul
>
</
li
>
<
li
> Assets
<
ul
data-role
=
listview
">
<
li
>Lawn Mower</
li
>
<
li
>Leaf Blower</
li
>
<
li
>Hedge Clippers</
li
>
</
ul
>
</
li
>
</
ul
>
# for (var i = 0; i <
assetList.length
; i++) { #
<li>#= assetList[i] #</
li
>
# } #
{ width: 40, field: "Description", title: "Description", attributes: { title: 'x<b>yy</b>zz' } },