KendoUI Grid does not invoke update function in popup mode with editable template - angularjs

I'm using a Kendo UI Grid with AngularJS. The grid has a 'popup' mode editable kendo template. The grid invokes the create, destroy & delete functions; however the update function won't get called. Strangely when I change the edit mode to 'inline', the update function is called. Below are the code snippets from my application :
Main UI Grid:
<div class="container-fluid">
<kendo-grid style="margin-top: 2em" k-options="ctrl.fundGridOptions" k-scope-field="kgrid" id="myGrid"></kendo-grid>
</div>
Edit Template:
<script id="edit-template" type="text/x-kendo-template">
<div class="container">
<div class="well">
Fund :
<select kendo-drop-down-list k-options="ctrl.fundOptions" style="width: 130px;" ng-model="dataItem.GenevaId"></select>
<!--<select kendo-drop-down-list k-data-source="ctrl.funds" style="width: 130px;" ng-model="dataItem.GenevaId"></select>-->
NAV Change Threshold
<input kendo-numeric-text-box k-min="0" k-max="100" k-ng-model="value" style="width: 60px;" ng-model="dataItem.NAVThreshold" />
NAV Source
<select k-data-source="ctrl.navSources" kendo-drop-down-list k-option-label="'-Select-'" style="width: 130px;" ng-model="dataItem.NAVSource"></select>
Frequency
<select k-data-source="ctrl.frequencyList" kendo-drop-down-list k-option-label="'-Select-'" style="width: 130px;" ng-model="dataItem.Frequency"></select>
Type
<select k-data-source="ctrl.typeList" kendo-drop-down-list k-option-label="'-Select-'" style="width: 130px;" ng-model="dataItem.Type"></select>
</div>
<div kendo-grid="ctrl.currencyKendoGrid" style="margin-top: 2em" k-options="ctrl.currencyGridOptions"></div>
</div>
</script>
Grid Options:
ctrl.fundGridOptions = {
dataSource: {
transport: {
update: function (options) {
DataSvc.updateFund(e.data).then(function (response) {
e.success(e.data);
});
},
},
schema: {
model: {
id: "FundId",
fields: {
FundId: { type: "number", editable: false, nullable: true },
GenevaId: { type: "string", editable: true },
NAVThreshold: { type: "number", editable: true },
NAVSource: { type: "string", editable: true },
Frequency: { type: "string", editable: true },
Type: { type: "string", editable: true },
}
}
},
},
sortable: true,
columns: [
{ field: "GenevaId", title: "Fund Name" },
{ field: "NAVThreshold*100", title: "NAV Threshold", template: '#=kendo.format("{0:p}", NAVThreshold)#' },
{ field: "NAVSource", title: "NAV Source" },
{ field: "Frequency", title: "Frequency" },
{ field: "Type", title: "Type" },
{ command: ["edit", "destroy"], title: " " }
],
detailTemplate: kendo.template($("#detail-template").html()),
detailInit: function (e) {
kendo.bind(e.detailRow, e.data);
},
dataBound: function (e) {
var grid = e.sender;
if (grid.dataSource.total() == 0) {
var colCount = grid.columns.length;
$(e.sender.wrapper)
.find('tbody')
.append('<tr class="kendo-data-row"><td colspan="' + colCount + '" class="no-data">Sorry, no data :(</td></tr>');
}
},
editable: {
mode: "popup",
template: kendo.template($("#edit-template").html()),
window: {
title: "Edit Fund Details",
animation: false,
height: "600",
width: "1200"
}
},
edit: function (e) {
if (e.model.Currencies)
ctrl.currencyKendoGrid.dataSource.data(e.model.Currencies);
},
toolbar: [
{
name: 'create',
text: 'Add Fund',
}],
};
Could anyone help me understand the reason why the 'update' function won't be called in 'popup' mode, but gets called in 'inline' mode ? Appreciate any responses in advance.

I know this is question old, but I came across it searching for an answer. I think the issue might be that your (and my) edit template uses ng-model binding to edit the dataItem ie we're using angularjs. This doesn't actually seem to change the dirty property on the dataItem. I solved the issue by using ng-change on each control. It's a pain, but seems to work.
<input id="Title" type="text" class="k-textbox" ng-model="dataItem.Title" ng-change="dataItem.dirty=true"/>

Related

How to disable checkbox of a row in kendo grid using javascript function

I have a kendo grid where columns are defined and 2 columns are checkbox type. based on some validation in the comments row data, I want to disable the checkbox of that particular row in the grid.
I have a separate javascript function that I am using for validation but I am not able to disable the checkbox of that row. I am adding both the kendo grid code and the javascript function.
Kendo Grid:
createGrid: function (data) {
$("#ProductGrid").kendoGrid({
dataSource: {
data: tableData
},
columns: [
{ field: "Accept", tilte: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Accept), "template": "<input type=\"checkbox\" />" },
{ field: "Decline", tilte: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Decline), "template": "<input type=\"checkbox\" />" },
{ field: "Item", tilte: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Item) },
{ field: "PartID", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.PartID) },
{ field: "Description", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Description), width:'300px' },
{ field: "SubPart", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPart) },
{ field: "SubPartDescription", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.SubPartDescription) },
{ field: "BusinessPartner", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.BusinessPartner) },
{ field: "ReqDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.ReqDelTM) },
{ field: "EarDelTM", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.EarDelTM) },
{ field: "EarDelDate", title: "Ear Del Date", hidden: true },
{ field: "Comments", title: commonLib.readMessageByUserLanguage(COLUMNTITLENAME.Comments) },
]
});
},
JS Function:
checkComments: function () {
var productGrid = $("#ProductGrid").data("kendoGrid");
var productGridData = productGrid.dataSource;
var noofproduct = productGridData.data().length;
var dataList = productGridData.data();
for (var i = 0; i < noofproduct; i++)
{
if (dataList[i].Comments == "Date not met")
{
(dataList[i].Accept.enable(false));
}
}
}
You can use kendo templates to disable your checkboxes by condition.
var data = [
{disabled: false},
{disabled: true},
{disabled: false}
];
$('#grid').kendoGrid({
dataSource: data,
columns: [{
title: "checkbox",
template: function (item){
return "<input type='checkbox' " + (item.disabled ? 'disabled': '') + ">"}
}]
});
You can try this solution here

How to toggle between week and workWeek in kendo ui scheduler

I have a requirement to toggle between the view in kendo UI scheduler, my view will be week but on checkbox click i want to change week view type between week and workWeek; how to do this?
Here is html
<label><input type="checkbox" ng-model="hideWeekend" ng-change="hideWeekends(hideWeekend);" value="true" />Hide Weekend</label>
<div id="team-schedule">
<div kendo-tooltip k-content="tooltipContent" k-filter="'.k-event'" class="k-group">
<div id="target"></div>
<div kendo-scheduler="weeklyScheduler" k-options="weeklySchedulerOptions" id="scheduler"></div>
</div>
</div>
JS code
$scope.schedulerDS = new kendo.data.SchedulerDataSource({
batch: true,
filter: {
logic: "or",
filters: [
{ field: "ownerId", operator: "eq", value: 1 },
{ field: "ownerId", operator: "eq", value: 2 }
]
}
});
var weekOrWorkWeek = 'workWeek';
$scope.loadWeeklySchedule = function (value) {
$scope.weeklySchedulerOptions = {
autoBind: false,
date: new Date(),
height: 600,
views: [{ type: value, selected: true, majorTick: 15, footer: false, allDaySlot: false }],
timezone: "Etc/UTC",
dataSource: $scope.schedulerDS,
resources: [
{
field: "ownerId",
title: "Owner",
dataSource: [
{ text: "Alex", value: 1, color: "#f8a398" },
{ text: "Bob", value: 2, color: "#51a0ed" },
{ text: "Charlie", value: 3, color: "#56ca85" }
]
}
]
};
};
$scope.hideWeekends = function (value) {
if (value == true) {
weekOrWorkWeek = 'workWeek';
$scope.loadWeeklySchedule(weekOrWorkWeek);
$scope.weeklySchedulerOptions.dataSource.read();
} else {
weekOrWorkWeek = 'week';
$scope.loadWeeklySchedule(weekOrWorkWeek);
$scope.weeklySchedulerOptions.dataSource.read();
}
};
$scope.loadWeeklySchedule(weekOrWorkWeek);
You can enable this view by adding the view type "workWeek" to the views array of the scheduler options object from the get go.
This will also show a view selection on the scheduler top toolbar but you can remove it by adding a CSS rule:
.k-scheduler-views {
display: none;
}
Switching between views can be done using the scheduler's view method:
$("#scheduler").data("kendoScheduler").view("ViewName")
Here's a Plunker with a demo.

Adding conditional value to angular ng-table

I want to add glyphicon to a column based on row value in ng-table component .For example if row.firstProperty==row.secondProperty then the glyph be added to column.I know how to do this in angular Grid UI but although I review documentations and examples but ‍‍‍‍‍‍I did not find any way in ng-Table.Can anyone suggest a solution to my issue?
Edit:My scenario is that I have a custom directive that it is used to produce many pages with same style and functionality by getting page data and in part of it ng-table is used by defining template for my directive.
ng-table.html
<table ng-table="to.tableParams" class="table" show-filter="{{::to.showFilter}}">
<tr ng-show="to.showHeaders">
<th class="th-select" ng-repeat="column in to.columns">{{column.title}}</th>
</tr>
<tr ng-repeat="row in $data">
<td ng-repeat="column in to.columns" ng-show="column.visible" sortable="column.field" ng-click="save(row)">
{{row[column.field][column.subfield] || row[column.field]}}
<span compile="column.getValue()" ></span>
</td>
</tr>
ngTable Columns is defined in Controllers and one of the columns is html values like glyphicons and buttons that is maked base on object named actionList which is defined in each controller like below:
vm.actionList = [
{
name: 'edit',
body: function (row) {
$state.go("editrule", {ruleId: row.id});
},
glyph: 'glyphicon-pencil',
permission: $scope.permission.edit,
showCondition:"true"
},
{
name: 'view',
body: function (row) {
$state.go("showrule", {ruleId: row.id});
},
glyph: "glyphicon-eye-open",
permission: $scope.permission.watch,
showCondition:"row.modifiedDate==row.createDate"
},
{
name: 'history',
body: function (row) {
$state.go("rulehistory", {ruleId: row.id});
},
glyph: "glyphicon-info-sign",
showCondition: "row.modifiedDate!=row.createDate",
permission: $scope.permission.history
}
];
.I put the logic for creating html column to my directive to prevent repeated code from controllers and delivering it to controllers and the controller part for defining columns is as below :
vm.columns = [
{
title: $translate.instant('URL'),
translate: "URL",
field: 'url',
visible: true,
alignment: 'text-align-lg-left'
},
{
title: $translate.instant('MATCH_TYPE'),
translate: "MATCH_TYPE",
field: 'matchType',
visible: true,
alignment: 'text-align-lg-center',
filter: [{lowercase: []}]
},
{title: $translate.instant('PRIORITY'), translate: "PRIORITY", field: 'priority', visible: true,alignment: 'text-align-lg-center'},
{title: $translate.instant('SOURCE'), tanslate: "SOURCE", field: 'source', visible: true,alignment: 'text-align-lg-center'},
{title: $translate.instant('CATEGORY'), translate: "CATEGORY", field: 'category', visible: true,alignment: 'text-align-lg-center'},
{
title: $translate.instant('CREATE_DATE'),
translate: "CREATE_DATE",
field: 'createdDate',
visible: true,
alignment: 'text-align-lg-center'
},
{
title: $translate.instant('LAST_CHANGE'),
translate: "LAST_CHANGE",
field: 'modifiedDate',
visible: true,
alignment: 'text-align-lg-center'
},
{title: $translate.instant('ACTION') ,translate: "ACTION", field: 'action', visible: true,alignment: 'text-align-lg-center'},
{title: '', visible: true, getValue: htmlValue, id: "actionList"}/*actions*/
];
function htmlValue() {
return $sce.trustAsHtml(actions);
}
The action value comes from directive that contains htmls.The Directive part is as below :
scope.html = function htmlValue() {
var html = "";
/*intentionaly angular ng-repeat not used*/
for (var i = 0; i < scope.actionList.length; i++) {
scope.entry = scope.actionList[i];
scope.permission = scope.entry.permission;
scope.myglyph = scope.entry.glyph;
if (typeof scope.entry.permission == 'undefined' || scope.entry.permission == true) {
debugger
html = '<button ng-show="{{entry.condition}}" type="button" class="btn btn-list" ng-click=' + $interpolate("{{entry.name}}(row)")(scope) + '> ' +
'<span class=\"glyphicon ' + $interpolate("{{entry.glyph}}")(scope) + '\"></span>' +
'</button>' + html;
console.log("this is test");
console.log(scope.test);
}
}
}
scope.$watch('refreshDataFilter', function (newValue, oldValue) {
/*EXTRACT ACTIONS*/
for (var i = 0; i < scope.actionList.length; i++) {
var entry = scope.actionList[i];
Object.defineProperty(scope, entry.name, {value: entry.body});
Object.defineProperty(scope, entry.showCondition, {value: "aaa"});
}
/*define table data filler*/
if (newValue == true) {
renderTable();
scope.refreshDataFilter = false;
}
});
The main problem is here that if I interpolate the values of entry.showCondition I always get the value of of last item in actionList. Is there any solution that I can make html part of table base on conditions?

How can i solve unknown provider issue in AngularJS with Kendo?

I want to populate data into kendo grid but I am getting an error unknown provider:Error: [$injector:unpr] Unknown provider: promiseObjProvider <- promiseObj <- ProcessController <- ProcessController. I am not sure where i am making mistake.Please see below code and advise how can i reslove this problem.
createEditProcess.html
<div class="panel panel-primary">
<div class="panel-heading">
<label ng-hide="editMode">Create New Process </label>
<label ng-show="editMode">Edit Process </label>
</div>
<div class="tabContent">
<form name="createProcessFormName" id="createProcessForm"
name="form" role="form" class="form-horizontal"
kendo-validator="validator" k-validate-on-blur="false" k-options="myValidatorOptions" ng-submit="validate($event)">
<div kendo-window="ERHPopup" k-title=""
k-width="350" k-height="100" k-visible="false" >
<div><span>This Process Has Risks And Controls Aligned To It. Please Review And Adjust Those If Necessary</span></div>
</div>
<div kendo-window="geographicLocationsPopup" k-title=""
k-width="350" k-height="100" k-visible="false" >
<div><span>This Process Has Risks And Controls Aligned To It. Please Review the Risks and Controls</span></div>
</div>
<div kendo-window="legalEntitiesPopup" k-title=""
k-width="350" k-height="100" k-visible="false" >
<div><span>This Process Has Risks And Controls Aligned To It. Please Review the Risks and Controls</span></div>
</div>
<div kendo-window="EPCFPopup" k-title=""
k-width="350" k-height="100" k-visible="false" >
<div><span>This Process Has Risks And Controls Aligned To It. Please Review The Risks And Controls</span></div>
</div>
<ng-include src="'views/createEditProcessContent.html'"></ng-include>
</form>
</div>
</div>
<div kendo-window="confirmationWin" options="confirmationWinOptions" class="confirmationWin"></div>
</script>
processController.JS
angular.module('riskAssessmentApp').controller('ProcessController', function($scope, Process,TreeViewData, $rootScope,
$routeParams, ViewEditPrcsService, kendoCustomDataSource, $http,EPCFHirachyInfo,ERhHirachyInfo,
$location,alert,ProcessUpdate, ihtRskRatingGridConfig, processTreeConfig, alignedRisksHeaderPallette, alignedRisksModal,
riskToControlGridDataService,controlToProcessConfig,savaControlToProcessGrid, riskRatingGrid,savaControlToProcessNoAlignGrid, processRatingGridConfig, Rating, alignExstRskDataService, alignedCtrlsHeaderPallette, alignExstRiskGrid,ConfirmationConfig,promiseObj) {
'use strict';
var resetDataPrt = function() {
return new kendo.data.DataSource({
data: $scope.processRating,
navigatable: true,
pageSize: 100
});
};
if($scope.editMode){
$scope.ihtRskRatingGridOptions = ihtRskRatingGridConfig.ihtRskRatingGrid;
ihtRskRatingGridConfig.ihtRskRatingGrid.dataSource = resetData2();
$scope.processRating = promiseObj.data;
$scope.processRatingGridOptions = processRatingGridConfig.processRatingGrid;
processRatingGridConfig.processRatingGrid.dataSource = resetDataPrt();
});
APP.JS
.when('/process/create', {
templateUrl : 'views/createEditProcess.html',
controller : 'ProcessController',
resolve: {
promiseObj: function(Rating){
return Rating.getAllProcessRatings();
}
}
})
processGrid.js
angular.module('riskAssessmentApp').value('processRatingGridConfig', {
processRatingGrid: {
columns: [{
field: 'ratingDateHistory',
title: 'History',
width: '8em'
}, {
field: 'irrComputed',
title: 'Process Inherent Risk Rating Computed',
width: '10em'
}, {
field: 'irrFinalOutcome',
title: 'Process Inherent risk business Final',
width: '10em'
}, {
field: 'mssControlFlag',
title: 'Missing controls',
width: '10em'
}, {
field: 'computedEffectiveRating',
title: 'Overall Control Effectiveness Computed',
width: '10em'
}, {
field: 'businessEffectiveRating',
title: 'Overall Control Effectiveness Business',
width: '10em'
}, {
field: 'effectiveJustification',
title: 'Control Effectiveness Business Justification',
width: '10em'
}, {
field: 'residualRiskComputed',
title: 'Residual Risk Computed',
width: '10em'
}, {
field: 'businessResidualRisk',
title: 'Residual Risk Business',
width: '10em'
}, {
field: 'residualRiskJustification',
title: 'Residual Risk Business Justification',
width: '10em'
}, {
field: 'riskDescription',
title: 'Risk Description',
width: '10em'
}, {
field: 'riskAcceptanceFlag',
title: 'Risk Acceptance',
width: '10em'
}, {
field: 'riskAcceptanceRationale',
title: 'Risk Acceptance Rationale',
width: '10em'
}]
},
});
Factory.js
angular.module("riskAssessmentApp").factory('Rating', function($http, $location) {
getAllUpdateQuestions: function (prcsSessionKey) {
return $http.get('app/processrating/rest/getProcessRating/' +prcsSessionKey);
},
getAllProcessRatings: function (processKey) {
return $http.get('app/processrating/rest/getProcessRatings/' + processKey);
}
};
});
In the line: <div class="panel panel-primary" ng-controller> remove ng-controller

Using AngularJS and KendoGrid

I am learning AngularJS and trying to use the Telerik KendoGrid in a directive. I have a directive that that will access a service and get some data. Part of the data will be used to populate an observable array in the directive. The html that is associated to that directive has another directive within it that will create a kendoGrid that should be editable. When I click on the update button I get an undefined error and the grid data disappears.
I define my array as follows:
$scope.currentData.event.submissionDates = new kendo.data.ObservableArray([
]);
and on success of call push the data into the array.
the grid is called as follows in the html:
<submission-grid class="grid-16" event="currentData.event" ng-show="currentData.event.eventID"></submission-grid>
This directive calls the following html file:
<div kendo-grid="grid"
k-columns="gridColumns"
k-selectable="true"
k-on-change="selected = data"
k-options ="mainGridOptions "
k-editable ="{'mode': 'inline', 'update': 'true'}"
and the backing js is:
(function () {
angular.module('app.submissionGrid', [])
.directive('submissionGrid', function () {
var ctrlr = function ($scope) {
$scope.gridColumns = [{
field: "SubmissionDueDate",
title: "Due Date",
format: "{0:MM/dd/yyyy}",
width: "100px"
}, {
field: "Source",
title: "Agency",
width: "100px"
}, {
field: "SubmissionFiledDate",
title: "Filed Date",
format: "{0:MM/dd/yyyy}",
width: "100px"
}, {
field: "SeverityCategory",
title: "Severity Category",
width: "100px"
}, { command: ["edit", ], title: " ", width: "200px" }
];
$scope.mainGridOptions = {
dataSource: {
data: $scope.event.submissionDates,
schema: {
model: {
id: "ReportId",
fields: {
SubmissionDueDate: { type: "string" },
Source: { type: "string" },
SubmissionFiledDate: { type: "string" },
SeverityCategory: { type: "string" }
}
}
},
}
}
}
return {
restrict: 'E',
templateUrl: 'App/Event/SubmissionGrid/submissionGrid.html',
controller: ctrlr,
transclude: false,
scope: {
event: '='
}
};
})
})();
Any advice would be appreciated.

Resources