angular
.module("app", ["kendo.directives"])
.controller("Grid", Grid)
// Grid controller constructor
function Grid() {
var vm = this;
//var scope = $scope;
vm.gridData = getDataSource();
console.log(vm.gridData)
vm.options = {
navigatable: true,
sortable: true,
editable: true,
columns: getColumns(),
dataSource: vm.gridData,
};
}
// Use to create a unique id for each row
var bookingId = 0;
// Row data
function RowData(bookingDate, carRego, carDescription, trailerRego, trailerDescription) {
// Generate a unique Id for this row (the data source needs this to identify the row updated!!)
this.bookingId = bookingId++;
this.bookingDate = bookingDate; // simple string
this.car = new RegoDescriptionPair(carRego, carDescription); // 2 tuple
this.trailer = new RegoDescriptionPair(trailerRego, trailerDescription); // 2 tuple
}
// 2 tuple container
function RegoDescriptionPair(rego, display) {
this.rego = rego;
this.display = display;
}
function getDataSource() {
var gridData = [
new RowData('1 jan 2015', 'C1', 'Car 1 - Red GMH sedan', 'TR1', 'Trailer 1'),
new RowData('2 jan 2015', 'C2', 'Car 2 - Blue Toyota', 'TR1', 'Trailer 1'),
new RowData('2 jan 2015', 'C2', 'Car 3 - Blue Toyota', 'TR2', 'Trailer 2'),
];
// Need to bind to a data source. If pass just the dataservice.getData(viewName) result,
// the grid takes a copy of this and put into it's own internal data source. If we pass this one,
// we can get at the modified values.
var dataSrc = new kendo.data.DataSource({
transport: {
read: function (e) {
e.success(gridData);
},
update: function (e) {
console.log("update is called: ", e);
var updateItem = e.data;
console.log("updated object : ", updateItem);
e.success();
},
create: function (e) {
console.log("create is called:", e);
console.log("create data is:", e.data);
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.