show or hide columns in kendo ui grid + angular js - angularjs

I am using Kendo UI grid in angular js. Grid is displaying correctly.
but I want to hide a particular column based on user type.
I have tried like below, but its not working.
Here my angular controller code:
$scope.blogGridOptions = {
dataSource: {
pageSize: 10,
autoBind: false,
transport: {
read: function (e) {
$http.get('/Blog/GetAllBlogs')
.then(function success(response) {
if (response.data.success) {
e.success(response.data.blogs);
}
});
gridCallback = e;
}
}
},
sortable: true,
pageable: true,
resizable: true,
filterable: true,
columns: [{
field: "BlogTitle",
title: "Blog Title",
width: "300px",
filterable: false
}, {
field: "BlogContent",
title: "Blog Content",
width: "300px",
filterable: false
}, {
field: "ApprovalStatus.ApprovalStatus",
title: "Approval Status",
width: "300px",
filterable: false
}, {
field: "Actions",
width: "300px",
template: function (e) {
var str = '';
str = str + 'Edit';
str = str + ' | Delete';
return str;
},
filterable: false
}, {
hidden: function (e) { return e.userDetails.UserTypeId == 1 ? false : true; } ,
title: "Approve",
template: function (e) {
return '<button type="button" class="btn btn-success" ng-click="blog.approveBlogs(dataItem,2)"><i class="fa fa-check"></i></button> <button type="button" class="btn btn-danger" ng-click="blog.ignoreBlogs(dataItem,3)"><i class="fa fa-close "></i></button>';
}
}]
}
MVC View code:
<div kendo-grid="blogGrid" options="blogGridOptions" id="gridBlog"></div>
if usertypeid is 1, that column should show, for other users, it should be hidden.
PLease help to resolve this issue.

You can use hidecolumn in your dataBound event that is on the options of the grid. Not sure where you are getting the userTypeId from, but let's say it's bound to the controller and the column's name is 'approved'
dataBound: function(e) {
if(vm.userDetails.UserTypeId !== 1){
this.hideColumn('approved');
}
},

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
}

Kendo UI Grid, Add Row Number in Template Angularjs

I want to bind kendo ui grid with custom checkbox template binding row index as checkbox Id like the following:
var record = 1;
$scope.mainGridOptions = {
dataSource: {
data: $scope.LockingList,
pageSize: 15
},
schema: {
// the data, which the data source will be bound to is in the "list" field of the response
data: "EmployeeList",
type: "json"
},
sortable: true,
filterable: {
extra: false,
operators: {
string: {
eq: "Is equal to",
neq: "Is not equal to"
}
}
},
pageable: true,
dataBound: function () {
this.expandRow(this.tbody.find("tr.k-master-row").first());
record = (this.dataSource.page() - 1) * this.dataSource.pageSize();
},
columns: [{
field: "EmployeeName",
title: "Employee Name",
},
{
template: "<input type='checkbox' id='#= ++record #' class='checkbox' ng-checked='dataItem.Locked' ng-click='LockByTask(dataItem)' /> <label for='#= ++record #'></label>",
title: "<input type='checkbox' id='header' title='Select all' ng-click='toggleSelectAll($event)' /><label for='header'></label>",
width: 60
}
],
editable: "popup"
};
I got record is not defined and can't bind row number.How to I do this? Thanks.

Kendo Grid Command parent controller function into directive-based template

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.

nested kendo grid - binding detailInit with data from service call

I have a angular directive which returns the kendo grid data source values (which is gridDataDisplayed). With the same data source, i have to bind it to a nested grid in detailInit.
scope.gridsource = new kendo.data.DataSource({
pageSize: options.pSize,
transport: {
read: function (options) {
scope.getDataMethod({ pageDetails: options }).then(function (gridDataDisplayed) {
options.success(gridDataDisplayed);
}, function (error) {
//error
});
}
},
detailInit: detailInitMethod
});
In the detailInitMethod i have the use the same data returned from service call and display only few columns from "gridDataDisplayed". How can i bind this to nested grid?
In my directive the template code is:
template: '<div><kendo-grid k-options="gridOptions" k-data-source="gridDataSource"></kendo-grid></div>',
Thanks in advance.
You can use the detail-template directive. Here is how:
<div ng-controller="MyCtrl">
<kendo-grid options="mainGridOptions" k-data-source="gridDataSource">
<div k-detail-template>
<div kendo-grid k-options="detailGridOptions"></div>
</div>
</kendo-grid>
</div>
<script>
angular.module("KendoDemos", [ "kendo.directives" ])
.controller("MyCtrl", function($scope){
$scope.gridDataSource = {
type: "odata",
transport: {
read: "//demos.telerik.com/kendo-ui/service/Northwind.svc/Employees"
},
pageSize: 5,
serverPaging: true,
serverSorting: true
};
$scope.mainGridOptions = {
sortable: true,
pageable: true,
dataBound: function() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
},
columns: [{
field: "FirstName",
title: "First Name",
width: "120px"
},{
field: "LastName",
title: "Last Name",
width: "120px"
}]
};
$scope.detailGridOptions = {
scrollable: false,
sortable: true,
dataSource: $scope.gridDataSource,
pageable: true,
columns: [
{ field: "City", title:"City", width: "56px" },
{ field: "Address", title:"Address", width: "110px" }
]
};
});
</script>
And a live demo: http://dojo.telerik.com/#korchev/UFIqa

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.

Resources