Kendo Grid Command parent controller function into directive-based template - angularjs

I am using Kendo UI's Angular grid. I am trying to pass a parent controller's function to a template that is based on another Angular directive (as a handler). I have a component with a controller that grabs the Kendo Grid options from a service.
(function () {
'use strict';
angular.module('ins.admin.userreg')
.component('insUserRegGrid', {
templateUrl: 'admin/user-registration/grid/user-reg-grid.tpl.html',
controllerAs: 'vm',
controller: controller
});
controller.$inject = ['insUserRegGridSvc', 'insUserRegRouteSvc', '$timeout'];
function controller(insUserRegGridSvc, insUserRegRouteSvc, $timeout) {
var vm = this;
vm.options = insUserRegGridSvc.getOptions();
vm.goToCreate = insUserRegRouteSvc.goToCreate;
vm.onActiveChange = function(value) {
console.log('changed' + value);
}
}
})();
Here are the options within that service (where the command template for Active is defined):
(function () {
'use strict';
angular.module('ins.admin.userreg')
.factory('insUserRegGridSvc', insUserRegGridSvc);
insUserRegGridSvc.$inject = ['_', 'insUserRegResrc', 'insFormatUtil', 'insAppSettingsSvc'];
function insUserRegGridSvc(_, insUserRegResrc, insFormatUtil, insAppSettingsSvc) {
function getOptions() {
return {
dataSource: {
transport: {
read: function (e) {
insUserRegResrc.getUsersWithRoles().$promise.then(function (response) {
response.map(function (i) {
i.UserID = i.UserId;
i.Url = insAppSettingsSvc.apiRoot + 'UserRegistration/Post/' + i.UserId;
i.FirstName = i.FirstName;
i.MiddleName = i.MiddleName;
i.LastName = i.LastName;
if (i.Role[0]) {
i.RoleName = i.Role[0].RoleName;
} else {
i.RoleName = "";
}
if (i.Reports[0]) {
i.Manager = i.Reports[0].FullName;
} else {
i.Manager = "";
}
i.Email = i.Email;
i.Active = i.IsActive;
});
response = _.orderBy(response, ['UserId'], ['asc']);
e.success(response);
});
}
},
pageSize: 10
},
resizable: true,
pageable: true,
editable: false,
sortable: true,
toolbar: "<a ng-click='vm.goToCreate()' class='btn ins-btn-update k-grid-add pull-left' title='Add New'>add</a>",
columns: [
{ title: 'User Id', field: 'UserID', sortable: true, width: 150 },
{ title: 'First Name', field: 'FirstName', sortable: true, width: 150 },
{ title: 'Last Name', field: 'LastName', sortable: true, width: 150 },
{ title: 'Role', field: 'RoleName', sortable: true, width: 150 },
{ title: 'Manager', field: 'Manager', sortable: true, width: 150 },
{ title: 'Email', field: 'Email', sortable: true, width: 150 },
{
title: 'Active',
width: 85,
command: [
{
name: "Toggle Active",
template: "<ins-toggle ins-id='activeToggle' ins-model='dataItem.Active' ins-on-change='vm.onActiveChange' ins-on-text='yes' ins-off-text='no' ins-enabled='true'></ins-toggle>"
}
]
},
{
width: 85,
command: [
{ name: "Edit", template: "<a class='k-button k-button-icontext k-grid-edit' data-toggle='tooltip' ui-sref='.edit({ userId: {{dataItem.UserID}}})' title='#: name #'> <span class='k-icon k-edit'></span> </a>" }
]
}
]
}
}
return {
getOptions: getOptions
};
}
})();
From the above code, focus on the following:
{
title: 'Active',
width: 85,
command: [
{
name: "Toggle Active",
template: "<ins-toggle ins-id='activeToggle' ins-model='dataItem.Active' ins-on-change='vm.onActiveChange' ins-on-text='yes' ins-off-text='no' ins-enabled='true'></ins-toggle>"
}
]
},
As you can see I am trying to pass the parent controller's vm.onActiveChange method as a scope attribute to ins-toggle. ins-toggle's ins-on-change scope attribute is setup as insOnChange: '&?' and works in other scenarios outside of Kendo's grid.
Does Kendo not allow for us to pass parent functions into directive's as a part of a template?

I have found out that it has nothing to do with Kendo, and it actually had to do with the Toggle directive I was using from UI-Bootstrap. Sorry everyone.

Related

How can I access UI-Grid isolate scope from outside?

There is a button outside of angular UI grid.
I would like to call a function on "Default" button click and post grid object parameter to the callback function.
There is a second example as well. But instead of posting grid object to the buttons inside of the grid I would like to post the grid object to the button outside of the grid.
To cut a long story short I would like to have an edit button outside of the grid (select one row mode is turned on) instead of adding a column of edit buttons without select row option.
Is it possible starting from v3.1.0?
http://plnkr.co/edit/JyiN7MejqkiTuvczsOk1
For some reason gridOptions.appScopeProvider is null when I expand $scope object in MainCtrl.Here is js-code sample:
angular.module('modal.editing', ['ui.grid', 'ui.grid.selection', 'ui.grid.edit', 'ui.bootstrap', 'schemaForm'])
.constant('PersonSchema', {
type: 'object',
properties: {
name: { type: 'string', title: 'Name' },
company: { type: 'string', title: 'Company' },
phone: { type: 'string', title: 'Phone' },
'address.city': { type: 'string', title: 'City' }
}
})
.controller('MainCtrl', MainCtrl)
.controller('RowEditCtrl', RowEditCtrl)
.service('RowEditor', RowEditor)
;
MainCtrl.$inject = ['$http', 'RowEditor', '$modal'];
function MainCtrl ($http, RowEditor) {
var vm = this;
vm.editRow = RowEditor.editRow;
vm.gridOptions = {
enableRowSelection: true,
enableRowHeaderSelection: false,
multiSelect: false,
selectionRowHeaderWidth: 35,
columnDefs: [
{ field: 'id', name: '', cellTemplate: 'edit-button.html', width: 34 },
{ name: 'name' },
{ name: 'company' },
{ name: 'phone' },
{ name: 'City', field: 'address.city' },
]
};
vm.test = function() {
debugger;
};
$http.get('http://ui-grid.info/data/500_complex.json')
.success(function (data) {
vm.gridOptions.data = data;
});
}
RowEditor.$inject = ['$rootScope', '$modal'];
function RowEditor($rootScope, $modal) {
var service = {};
service.editRow = editRow;
function editRow(grid, row) {
debugger;
$modal.open({
templateUrl: 'edit-modal.html',
controller: ['$modalInstance', 'PersonSchema', 'grid', 'row', RowEditCtrl],
controllerAs: 'vm',
resolve: {
grid: function () { return grid; },
row: function () { return row; }
}
});
}
return service;
}
function RowEditCtrl($modalInstance, PersonSchema, grid, row) {
var vm = this;
vm.schema = PersonSchema;
vm.entity = angular.copy(row.entity);
vm.form = [
'name',
'company',
'phone',
{
'key': 'address.city',
'title': 'City'
},
];
vm.save = save;
function save() {
// Copy row values over
row.entity = angular.extend(row.entity, vm.entity);
$modalInstance.close(row.entity);
}
}
That is exactly what onRegisterApi is for:
vm.gridOptions = {
enableRowSelection: true,
enableRowHeaderSelection: false,
multiSelect: false,
selectionRowHeaderWidth: 35,
columnDefs: [
{ field: 'id', name: '', cellTemplate: 'edit-button.html', width: 34 },
{ name: 'name' },
{ name: 'company' },
{ name: 'phone' },
{ name: 'City', field: 'address.city' },
],
onRegisterApi: function (gridApi){
vm.gridApi = gridApi;
}
};
Then the gridApi will be in your scope (vm.gridApi) and you can access the grid and all the rows in gridApi.grid.
Hope this helps.

How can i popup detail for each record using Angularjs with kendo modal dialog?

I am using Kendo Ui grid to display data , i have been searching for solution for detail record popup dialog using angular with kendo.once user click detail for each record i want to popup complete detail in dialog box.
so far i have implemented below code...
HTML
<div kendo-grid="lrrSearchGrid" options="lrrSearchGridOptions">
</div>
CTRL.JS
$scope.lrrSearchData = {};
$scope.lrrSearchData = null;
$scope.mappedLRRSearchData = {};
$scope.mappedLRRSearchData = null;
// Search
$scope.searchLRRs = function () {
SubCategory.searchLRRBasedOn(1, $scope.search.searchBy, $scope.search.searchParam).then(function (data) {
$scope.lrrSearchData = data.data;
$scope.lrrSearchGrid.setDataSource(new kendo.data.DataSource({
data: $scope.lrrSearchData,
pageSize: 5
}));
}, function (err) {
if (err.status === 404) {
$scope.searchError = 'No Records Found';
}
});
};
$scope.gotoSubCats = function() {
$state.go('app.subCats');
};
// Setting the LRR Search Data
$scope.lrrSearchGridOptions = lrrSearchGridConfig.lrrSearchGrid;
lrrSearchGridConfig.lrrSearchGrid.dataSource = resetLRRSearchData();
$scope.mappedLRRGridOptions = lrrSearchGridConfig.mappedLRRGrid;
lrrSearchGridConfig.mappedLRRGrid.dataSource = resetMappedLRRSData();
Config.js
lrrSearchGrid: {
sortable: true,
pageable: {
previousNext: false,
pageSizes: false
},
scrollable: true,
filterable: true,
columns: [
{
field: 'regionName',
title: 'Jurisdiction',
width: '32px'
}, {
field: 'regInvetoryName',
title: 'Inventory',
width: '32px'
},{
field: 'ruleIdentifier',
title: 'Rule Id',
width: '25px'
}, {
field: 'citationValue',
title: 'Rule Citation',
width: '30px'
}, {
field: 'ruleName',
title: 'Rule Standard Name',
width: '30px'
}, {
field: 'subPartId',
title: 'Subpart Id',
width: '30px'
}, {
field: 'subpartCitation',
title: 'Subpart Citation',
width: '40px'
}, {
field: 'subpartRuleName',
title: 'Subpart Standard Name',
width: '40px'
},{
field: 'Detail',
title: 'Action',
width: '40px',
filterable:false,
template : function(dataItem) {
if (typeof dataItem.lrrDetail == "string") {
return "<a href=\</a>";
}
}
}
]
}
Thanks in advance i will appreciate any help.
I have created a fiddle for the same,check if it helps you
: http://jsfiddle.net/Sowjanya51/6r01vccj/3/
you can use the custom command option of kendo grid to achieve this.

filtering cards based on PortfolioItem selected for CardBoard

I am creating a rally sdk2 app, which shows Rally.ui.dialog.ChooserDialog of PortfolioItems like MMF, Epic and Program
When multiple MMFs or Epics or Programs are selected, show the features based on those filters, but cards are not getting. Something I am not able to figure out.
below is my some of the code
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
items:[{ xtype: 'container', itemId: 'filter_box', padding: 5},{xtype:'container',itemId:'button_box',layout:{type:'hbox'}, padding: 10}],
logger: new Rally.technicalservices.logger(),
launch: function() {
this.down('#button_box').add({
xtype: 'rallybutton',
text: 'Filter',
itemId: 'run-button',
scope: this,
handler: this._run,
margin: '0 10 0 95'
});
},
_drawCardBoard: function(records){
var filters = null;
alert("hi there");
console.log("context");
var me = this;
if (records[0].data.PortfolioItemTypeName == "MMF") {
console.log("context name", records[0].data.FormattedID);
filters = Ext.create('Rally.data.QueryFilter',{
property: 'Parent.FormattedID',
operator: '=',
value: records[0].data.FormattedID
});
} else if (records[0].data.PortfolioItemTypeName == "Epic") {
filters = Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.FormattedID',
operator: '=',
value: records[0].data.FormattedID
});
} else if (records[0].data.PortfolioItemTypeName == "Program") {
filters = Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.Parent.FormattedID',
operator: '=',
value: records[0].data.FormattedID
});
}
if (records.length > 1) {
for ( var i=1;i<records.length;i++ ) {
if (records[i].data.PortfolioItemTypeName == "MMF") {
console.log("context name 2", records[i].data.FormattedID);
filters = filters.or(Ext.create('Rally.data.QueryFilter',{
property: 'Parent.FormattedID',
operator: '=',
value: records[i].data.FormattedID
}));
} else if (records[i].data.PortfolioItemTypeName == "Epic") {
filters = filters.or(Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.FormattedID',
operator: '=',
value: records[i].data.FormattedID
}));
} else if (records[i].data.PortfolioItemTypeName == "Program") {
filters = filters.or(Ext.create('Rally.data.QueryFilter',{
property: 'Parent.Parent.Parent.FormattedID',
operator: '=',
value: records[i].data.FormattedID
}));
}
}
}
console.log("filters values", filters.toString());
this.cardboard = Ext.create('Rally.ui.cardboard.CardBoard',{
types: ['PortfolioItem/Feature'],
attribute: 'Release',
columnConfig: {
xtype: 'rallycardboardcolumn',
displayField: 'Name',
valueField: '_ref',
plugins: [
{ptype:'rallycolumndropcontroller'},
{ptype:'rallycardboardcardrecordprocessor'},
{ptype:'tscolumnheaderupdater'} /*,
{ptype:'tscolumnheaderupdater', field_to_aggregate: 'LeafStoryPlanEstimateTotal'}*/
],
},
storeConfig: {
filters: filters,
context: this.getContext().getDataContext()
},
cardConfig: {
showIconsAndHighlightBorder: false,
fields: [
'FormattedID',
'Name',
'Parent',
'ReleaseDate',
'ReleaseStartDate',
{ name: 'Project', renderer: me._renderProject },
{ name: 'PercentDoneByStoryPlanEstimate' },
{ name: 'c_FeatureEstimate', fetch: ['c_FeatureEstimate'] }
],
listeners: {
added: function(card,container){
me.logger.log(this,card,container);
},
fieldClick: function(eOpts) {
me.logger.log(this,eOpts);
if ( eOpts == "PercentDoneByStoryPlanEstimate" ) {
me._showDoneTooltip(eOpts,this);
}
}
}
}
});
_run: function() {
this._parents = {};
var me = this;
Ext.create('Rally.ui.dialog.ChooserDialog', {
width: 470,
autoScroll: true,
height: 500,
title: 'Select to Filter',
pageSize: 100,
closable: false,
selectionButtonText: 'Filter',
multiple: true,
artifactTypes: ['PortfolioItem/MMF','PortfolioItem/Epic', 'PortfolioItem/Program'],
autoShow: true,
storeConfig:{
fetch: ['Name','PortfolioItemTypeName', 'Parent']
},
listeners: {
scope: me,
artifactChosen: function(selectedRecord) {
console.log("selectedRecord", selectedRecord);
me._drawCardBoard(selectedRecord);
}
}
});
},

Kendo Grid with Angular not always showing rows

I am sporadically seeing my grid not show any rows when in fact there are rows bound to the grid. Does anyone see if my usage pattern is incorrect when integrating angular? Thanks!
EDIT - It also appears the strange behavior only occurs when leaving the page and coming back to the page for a full refresh.
$scope.init = function () {
$scope.loading.busy.right = consigneeService.api.getActivity(session.consignee.id()).then(function (result) {
$scope.details = result;
$scope.gridOptions.dataSource.read();
});
};
$scope.gridOptions = {
dataSource: new kendo.data.DataSource({
transport: {
read: function (options) {
options.success($scope.details);
}
}
}),
sortable: {
allowUnsort: false
},
autoBind: false,
columns: [
{ field: 'activityDate', title: 'Activity Date', width: '150px', template: "{{ dataItem.activityDate | cmsUTCToLocal : 'short' }}" },
{ field: 'activityDetails', title: 'Activity Details', width: '300px;' },
{ field: 'createUserId', title: "Created By", width: "125px" }
]
};

Populate ng-grid by another grid selection

I am trying to populate a ng-grid based on the JSON array returned from a selection of a first ng-grid. As of right now I can get the JSON array displayed onto the screen but I cannot navigate deeper into the JSON array or get anything to display in the second grid. I have the controller code attached and the plnkr can be found at http://plnkr.co/edit/nULoI4?p=info.
'use strict';
function ArticleDataCtrl($rootScope, $scope, articleDataService) {
articleDataService
.getArticles()
.then(
function(articles) {
$rootScope.articles = articles;
$scope.articleGridItems = articles.data.specialMerchandise.specialMerItem;
});
$scope.articleGrid = {
data: 'articleGridItems',
showGroupPanel: false,
multiSelect: true,
checkboxHeaderTemplate: '<input class="ngSelectionHeader" type="checkbox" ng-click="getDeliveryLocations()" ng-model="allSelected" ng-change="toggleSelectAll(allSelected)"/>',
showSelectionCheckbox: true,
selectWithCheckboxOnly: true,
enableColumnResize: true,
selectedItems: [],
columnDefs: [{
field: 'soMerArticleNbr',
displayName: 'Article'
}, {
field: 'soMerOrdQty',
displayName: 'Qty'
}, {
field: 'soArtDeliveryCode',
displayName: 'Delivery Code'
}, {
field: 'dsgnSysRecDesc',
displayName: 'Description'
}]
};
//This is not being called on header template click
$scope.getDeliveryLocations = function() {
$scope.deliveryLocationData = $scope.commonDeliveryLocations;
};
$scope.selections = $scope.articleGrid.selectedItems;
var jsonObject = JSON.stringify($scope.selections);
//Thought a json problem occured here...was wrong
$scope.test = jsonObject.deliveryLocations;
$scope.deliveryGrid = {
data: 'selections',
showGroupPanel: false,
multiSelect: false,
columnDefs: [{
displayName: 'Delivery Methods'
}]
};
}
myApp.controller('ArticleDataCtrl', ['$rootScope', '$scope',
'articleDataService', ArticleDataCtrl
]);
So instead of trying to use angular's built in checkboxes I used my own with a custom method on ng-click. Here is the code and the plunker demonstrating the functionality is http://plnkr.co/edit/nULoI4?p=info.
'use strict';
function ArticleDataCtrl($rootScope, $scope, articleDataService) {
articleDataService
.getArticles()
.then(
function(articles) {
$rootScope.articles = articles;
$scope.articleGridItems = articles.data.specialMerchandise.specialMerItem;
});
$scope.articleGrid = {
data: 'articleGridItems',
showGroupPanel: false,
multiSelect: false,
enableColumnResize: true,
selectWithCheckboxOnly: true,
columnDefs: [{
/*
headerCellTemplate: myHeaderCellTemplate,
*/
cellTemplate: '<input id="checkSlave" name="articleCheckBox" ng-checked="master" type="checkbox" ng-click="getDeliveryLocation(row.entity)" />'
}, {
field: 'soMerArticleNbr',
displayName: 'Article'
}, {
field: 'soMerOrdQty',
displayName: 'Qty'
}, {
field: 'soMerUOIDesc',
displayName: 'UOM'
}, {
field: 'soArtDeliveryCode',
displayName: 'Delivery Code'
}, {
field: 'soMerShrtMerDesc',
displayName: 'Description'
}, {
field: 'soMerDesc',
displayName: 'Vendor'
}]
};
$scope.getDeliveryLocation = function(deliveryLocation) {
$scope.deliveryLocationData = deliveryLocation.deliveryLocation;
for (var i = 0; i < $scope.deliveryLocationData.length; i++) {
var locationId = $scope.deliveryLocationData[i].dlvryLocId;
var locationDesc = $scope.deliveryLocationData[i].dlveryLocDesc;
$scope.deliveryLocationData[i].dlvryLocId = locationId + locationDesc;
}
return $scope.deliveryLocationData;
};
return $scope.deliveryLocationData;
};
$scope.deliveryGrid = {
data: 'deliveryLocationData',
showGroupPanel: false,
multiSelect: false,
columnDefs: [{
field: 'dlvryLocId',
displayName: 'Delivery Methods'
}]
};
$scope.customerGroup = {
value: 'DIY'
};
}
myApp.controller('ArticleDataCtrl', ['$rootScope', '$scope',
'articleDataService', ArticleDataCtrl
]);

Resources