Kendo UI Grid with Angular Web Api Multi-dimensional model - angularjs

I am trying to use serverPaging with the Kendo UI grid. In order to pass the total pages. I am passing a model which consists of the data list, and the total count. My problem is that I can't figure out how to parse the model in the Kendo grid.
Here is my Controller code:
$scope.mainGridOptions = {
dataSource: {
transport: {
read: {
url: '/SSQV4/SSQV5/Search/GetSearch',
type: "GET"
}
},
schema: {
total: "Total"
},
pageSize: 25,
serverPaging: true
},
sortable: true,
pageable: true,
resizable: true,
columns: [{
field: "CompanyID",
title: "Company ID"
}, {
field: "CompanyName"
}, {
field: "City"
}, {
field: "State"
}, {
field: "Deficiencies"
}]
};
The data returned is a list ("results"), and the recordcount ("Total"). Normally, I would use a service to get the data and parse the two like below:
myService.GetSearch()
.success(function(data)){
$scope.myDataList = data.results;
$scope.myDataCount = data.Total;
})
I cannot figure out how to use "results" and "Total" in the Kendo Grid when it is returned by my web api.
Any assistance is greatly appreciated.

I figured this one out. I had to add "results" to the schema. This worked:
$scope.mainGridOptions = {
dataSource: {
transport: {
read: {
url: '/SSQV4/SSQV5/Search/GetSearch',
type: "GET"
}
},
schema: {
data: "results",
total: "Total"
},
pageSize: 25,
serverPaging: true
},
sortable: true,
pageable: true,
resizable: true,
columns: [{
field: "CompanyID",
title: "Company ID"
}, {
field: "CompanyName"
}, {
field: "City"
}, {
field: "State"
}, {
field: "Deficiencies"
}]
};

Related

dropdownlist doesn´t run in mode table (Kendo grid in angularjs)

Need a demo or source when use a dropdownlist in mode table on filter column in kendo grid of jquery or angularjs.
{
field: "VolunteerConnectName",
title: vm.module_resources.VolunteerConnect_Text,
filterable: {
cell: {
template: function (args) {
args.element.kendoDropDownList({
dataSource: args.dataSource,
optionLabel: "Seleccione",
dataTextField: "VolunteerConnectName",
dataValueField: "VolunteerConnectName",
valuePrimitive: true
});
},
operator: "eq",
showOperators: false
},
},
width: "20%"
},
filterable and values for rows and values for mode table.
{
field: "VolunteerConnect",
title: vm.module_resources.VolunteerConnect_Text,
width: "20%",
values: [
{ text: "Sí", value: true },
{ text: "No", value: false }
],
template: function (dataItem) {
var content = "";
content = (dataItem.VolunteerConnect) ? "Sí" : "";
return content;
},
filterable: true
}

Dynamic bind kendo grid dataSource binded to directive

I create dataSourec in the controller
$scope.dataSource = new kendo.data.DataSource({
transport: {
read: function (e) {
e.success(response.data.value);
}
},
serverFiltering: true,
serverSorting: true,
pageSize: 20,
schema: {
model: {
fields: {
languageId: { type: 'number', editable: true, nullable: false },
dateStart: { type: 'date', ediitable: true },
dateEnd: { type: 'date', ediitable: true },
count: { type: 'number', editable: true, nullable: false }
}
}
}
});
Then I bind it to my component
<div data-ng-if="!displayList">
<analytics-grid data-data-source="dataSource"></analytics-grid>
</div
where I add it to options of my grid
ctrl.gridOptions = {
dataSource: ctrl.dataSource,
sortable: true,
pageable: true,
columns: [{
field: "languageId",
title: "language",
width: "120px",
filterable: false,
values: _languagesLookupDS.data().toJSON()
}, {
field: "count",
title: "count"
}, {
field: "dateStart",
title: "dateStart"
}, {
field: "dateEnd",
title: "dateEnd"
}],
editable: {
mode: 'popup',
confirmation: true
},
messages: { commands: { create: "" } }
};
and then bind to kendo grid in the component view
<kendo-grid data-k-options="$ctrl.gridOptions" data-k-ng-delay="$ctrl.gridOptions" data-k-rebind="$ctrl.dataSource"></kendo-grid>
I show component view when someone switch the button(data-ng-if="!displayList" in code above). I have to switch button to displayList = true and then again to displayList = false, to update grid data, why it do not update dynamicly when dataSource change in my controller, and button is set to show kendoGrid?
I have resolved the problem by declare ctrl.gridOptions as function
ctrl.gridOptions = function () {
return {
dataSource: ctrl.dataSource,
sortable: true,
columns: [{
field: "languageId",
title: "language",
width: "120px",
filterable: false,
values: _languagesLookupDS.data().toJSON()
}, {
field: "count",
title: "count"
}, {
field: "dateStart",
title: "dateStart"
}, {
field: "dateEnd",
title: "dateEnd"
}]
};
}
and then bind it to the view
<kendo-grid data-k-scope-field="$ctrl.analyticsGrid" data-k-options="$ctrl.gridOptions()" data-k-rebind="$ctrl.dataSource"></kendo-grid>
My job mate told that problem occurred couse view was looking for object of options and don't know how to resolve it when dataSource change. Right now it just call method and get options with new dataSource.

Kendo Unable to get property 'data' of undefined or null reference

I am using Kendo UI grid with Angular. I am trying to send grid updates to my MVC controller, but when I click the Update button in the grid I am receiving the error "Unable to get property 'data' of undefined or null reference"
Here is my Angular controller code for my grid:
$scope.gridOptions = {
dataSource: new kendo.data.DataSource({
transport: {
read: {
method: "GET",
url: "/SSQV4/SSQV5/Search/GetBusinessUnits"
},
update: {
method: "POST",
url: "/SSQV4/SSQV5/Operator/UpdateBusinessUnit"
}
},
schema: {
model: {
id: "ProductID",
fields: {
intOrder: { editable: false },
OperatorBusinessUnitID: { editable: false },
vchDescription: { editable: true },
vchOperatorSystemID: {editable: true}
}
}
},
sort: { field: "intOrder", dir: "asc" }
}),
batch: false,
reorderable: true,
sortable: false,
editable: "inline",
columns: [
{ template: '<i class="fa fa-chevron-circle-up" style="cursor:pointer" ng-click="MoveUp(#=OperatorBusinessUnitID#)"></i> <i class="fa fa-chevron-circle-down" ng-click="MoveDown(#=OperatorBusinessUnitID#)" style="cursor:pointer"></i>', title: "List Order", width:100 },
{ field: "intOrder", hidden: true},
{ field: "OperatorBusinessUnitID", title: "Business Unit ID" },
{ field: "vchDescription", title: "Business Unit Name" },
{ field: "vchOperatorSystemID", title: "Operator System ID"},
{
command: [
{ name: "edit", text: " " },
{ name: "destroy", text: " " },
], title: "Action"
}
]
};
Here is my MVC controller method:
public ActionResult UpdateBusinessUnit(OperatorBusinessUnitModel form)
{
CompanyClient.UpdateBusinessUnit(form);
var businessunits = CommonClient.GetBusinessUnitsByMajorID(UserInfo.intMajorID);
return Json(businessunits, JsonRequestBehavior.AllowGet);
}
There were two issues causing my problem here. First, the scheme had Product ID as the id, and it should have been OperatorBusinessUnitID. (That's what I get for copying examples.) The issue is that the UpdateBusinessUnit method in my MVC controller needed to be changed to a void rather than an ActionResult returning the entire recordset. It seems to be working correctly now.

Kendo Angular grid inline editing

I want to implement inline editing in Kendo Angular Grid. My Grid HTML is as below in an angular view
<div kendo-grid="bankRegisterGrid" k-options="bankRegisterGridOptions" ></div>
My controller code is as
$scope.bankRegisterGridOptions = {
resizable: true,
dataSource: {
batch: true,
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number", nullable: false },
ReferenceNo: { type: "string"},
AHead: { type: "string"},
Credit: { type: "number" },
Debit: { type: "number"},
ReconDescription: { type: "string"}
}
}
},
type: "json",
transport: {
read: "../Accounting/api/AccBankRegister/GetPaged",
update: {
url: "../Accounting/api/AccBankRegister/Update",
dataType: "json",
type: "Post"
},
destroy: {
url: "../Accounting/api/AccBankRegister/Update",
dataType: "json",
type: "Post"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
pageSize: 10
},
pageable: true,
columns: [{
field: "ReferenceNo",
title: "Ref. No",
type: "string",
width: "90px"
}, {
field: "AHead",
title: "Account Head",
type: "string",
width: "250px"
},
{
field: "Credit",
title: "Credit",
type: "number",
width: "90px"
},
{
field: "Debit",
title: "Debit",
type: "number",
width: "90px"
},
{
field: "Comments",
title: "ReconDescription",
type: "string",
width: "90px"
},
{ command: ["edit", "destroy"], title: " ", width: "130px" }],
editable: "inline"
};
Af first when the layout page open the url is xxx:2815/Accounting/Accounting#/ and when I click the BankRegister menu item the url is then xxx:2815/Accounting/Accounting#/BankRegister/. Now the grid open with data. When I click Edit button I see error in firebug:
'Error: Syntax error, unrecognized expression: unsupported pseudo: kendoFocusable .... jquery-1.9.0.js (line 4411, col 7)'.
In every row Edit Button click it comes. When I click cancel button in row it goes to home page and the url is xxx:2815/Accounting/Accounting#/. What is the problem?

angularjs kendo datasource data length zero

I'm trying to get my grid (created by angular directive) populated with data, but it is not populating.
Here's my grid declaration:
<div id="dayTypesGrid" kendo-grid k-options='dayTypesGridOptions'></div>
Here's code from my angular controller:
$scope.dayTypesGridOptions = {
schema: {
model: {
id: "description",
fields: {
description: { editable: false, nullable: false },
numberOfDays: { type: "number", validation: { required: true, min: 0} }
}
}
},
columns: [{
field: "description",
title: "Day Type"
}, {
field: "numberOfDays",
title: "Number of Days"
}]
};
So far so good. The grid is instantiated, and I see the two columns. And my angular controller executes my data fetch call, and I store the result in an array $scope.viewModel.dayTypes.
Using the browser dev tools, I can see that $scope.viewModel.dayTypes indeed contains the array of 7 records.
I now want to display those 7 records in the grid, and I do so as follows:
var ds = new kendo.data.DataSource({data: $scope.viewModel.dayTypes});
$('#dayTypesGrid').data('kendoGrid').dataSource = ds;
After that last line of code, my grid still remains empty. Using the browser dev tools, I see that ds.data.length is zero.
What am I missing?
What you're looking for is the setDataSource method:
$('#dayTypesGrid').data('kendoGrid').setDataSource(ds);
Here is how I do it in my project and this works for me. Your mileage may vary because you're using data instead of a transport URL, but I noticed the structure of your grid configuration is a bit different than mine. For example, I define the schema when I create my datasource:
var datasource = new kendo.data.DataSource({
transport: {
read: {
url: "url/to/my/service",
dataType: "json"
}
},
schema: {
data: "results"
}
};
var gridConfig: {
dataSource: dataSource,
rowTemplate: $templateCache.get("modules/reports/row.html"),
height: 500,
scrollable: true,
groupable: true,
filterable: true,
pageable: true,
reorderable: true,
sortable: true,
resizable: true,
"columns": [
{
"field": "status",
"title": "Status",
"width": 200
},
{
"field": "actions",
"title": "Actions",
"width": 200
}
]
}
};

Resources