KendoGrid with Angular ng-repeat - angularjs

I have kendo-grids in Angular ng-Repeat and serach options on the grids data.
I want to refresh the grids on search.
This is my code and it doesn't refresh the grids ($("#kendoGrid1").data("kendoGrid") is undefined), what Is the fix for this?
html
<article ng-repeat="(key,val) in gridsResult" >
<h2 class="tableTitle">{{key}}</h2>
<div kendo-grid="kendoGrid{{$index}}" k-options="getGridSlice('{{key}}')"></div>
</article>
js
$scope.getGridSlice = function (index) {
var data = $scope.gridsResult[index];
return {
dataSource: {
data: data
}
},
columns: [
{ field: "aa", title: " ", attributes: { "class": "k-header",style:"text-align:center;" }, width:"33px" },
{ field: "bb", title: "IF", template: rowTemplate.replace(/XX/g, 'IF')}
],
scrollable: false,
noRecords: true,
}};
scope.onSearch function -
$("#kendoGrid1").data("kendoGrid").datasource.read();

I found the answer!
The $digest dosen't work on functions so I added k-data-source based on a scope parameter not scope function.
(you need to pull the data from the DB grouped by the grids category)
<article class="tradescreenTable" ng-repeat="(key,val) in gridsResult" ng-class="{'bestAverage': bestAverageSelected}">
<h2 class="tableTitle">{{key}}</h2>
<div kendo-grid k-data-source="{{val}}" k-options="gridOptions"></div>
</article>
And k-options
$scope.gridOptions = {
columns: [
{ field: "aa", title: " ", attributes: { "class": "k-header",style:"text-align:center;" }, width:"33px" },
{ field: "bb", title: "IF", template: rowTemplate.replace(/XX/g, 'IF')}
],
scrollable: false,
noRecords: true,
};

You also need to refresh the grid:
$("#kendoGrid1").data("kendoGrid").datasource.read();
$("#kendoGrid1").data("kendoGrid").refresh();

kendo-grid="kendoGrid{{$index}}" binds the grid to the $scope - you don't need to use jQuery for this (and besides, you're not setting an id on the DOM element, so $("#kendoGrid1") is never going to work with your code as it is now).
$scope.kendoGrid1.datasource.read();
The one caveat to this is that I haven't ever tried dynamically setting the name for a Kendo Grid, so I'm not 100% that it works.

Related

How to show bootstrap tooltip dynamic data where tooltip has html content

I am trying to load data from the grid inside tooltip. This tooltip is generated once the user hovers on first column inside ui-grid. I want to use bootstrap and html of tooltip is displaying as required. I have tried several ways but now the data is not showing.
Please see the attached picture. I want actual value of {{row.entity.Status}}
Please see the current code for reference
https://codepen.io/brainzest/pen/bmqgLy?editors=0011
angular.module('GridDemo', ['ngTouch', 'ui.grid', 'ui.grid.cellNav', 'ui.grid.pinning']).controller('MainCtrl', function($scope,uiGridConstants,$sce){
$scope.equipData = [
{ Status: "Maintenance",
PackageName: "Package 1",
Hours: "15,000",
},
{ Status: "Running",
PackageName: " Package 2",
Hours: "15,000",
},
{ Status: "Running",
PackageName: "Package 3",
Hours: "15,000",
},
{ Status: "Running",
PackageName: "Package 4",
Hours: "15,000",
},
];
$scope.gridOptions = {
enableSorting: true,
enableColumnResizing : true,
enableColumnMenus:false,
columnDefs: [{ field: 'PackageName', cellTemplate:'<div data-toggle="tooltip" title="\<table class=table-borderless><tbody><tr><td class=gray>Status</td><td class=yell>Data 2</td></tr><tr><td class=gray>Status</td><td class=yell>{{row.entity.Status}}</td></tr></tbody></table>" data-html="true" data-placement="right" ><div class="ui-grid-cell-contents">{{ COL_FIELD }}</div></div>'},
{ field: 'Hours'}],
data:$scope.equipData
};
}).directive('toggle', function(){
return {
restrict: 'A',
link: function(scope, element, attrs){
if (attrs.toggle=="tooltip"){
$(element).tooltip();
}
}
};
});
if you are looking for something more angular you should do it this way:
<div class="grid-tooltip" tooltip="{{row.entity.Status}}" tooltip-placement="left">
<div class="ui-grid-cell-contents">
{{ COL_FIELD }}
</div>
</div>

Kendo Grid pagination button shows in vertical format

I have a Kendo grid in my application and I am binding data to it through REST call. When the grid load first time, the buttons doesn't show up. Below is the example:
There are 400+ items in the grid, currently it is configured to show only 50 items per page. But the problem is I am not able to see options to visit second/next page.
Option of second page is visible when I change items per page. Like If I change option from 50 - 100. I am able to see other page number.
This is the second Problem. Page number appears in vertical way instead of horizontal.
I need help in solving below issues:
When Page Load pagination options should be displayed as they are suppose to be.
Pagination numbers should appear in horizontal way not in vertical way.
Below is my code snippet:
$scope.mainGridOptions = {
editable: true,
pageable: {
pageSizes: [15,25,50,100]
},
navigatable: true,
sortable: true,
filterable: true,
dataSource: {
type: "odata",
pageSize: 50,
batch: false,
requestEnd: function(e) {
if (e.type != 'read')
{
$('#grdItemizations').data('kendoGrid').dataSource.read();
}
},
schema: {
model: {
id: "Id",
fields: {
Id: { type: "number", editable: false },
Title: { type: "string",editable: false }
}
},
data: function (data) {
return data.d && data.d.results ? data.d.results : [];
}
},
transport: {
parameterMap: function (data, type) {
if (type != "read") {
var strIfy = kendo.stringify({
"__metadata": type != "create" ? { "type": },
"Title": data.Title,
"Id": type != "create" ? data.ID : undefined
});
return strIfy;
}
return kendo.data.transports["odata"].parameterMap.apply(this, arguments);
},
read: {
},
update: {
},
create: {
},
error: function (e) {
alert("Status: " + e.status + "; Error message: " + e.errorThrown);
}
},
},
columns: [
{ field: "Id", title: "ID" , width: "60px"},
{ field: "Title", title: "Analytic Inventory Description" , width: "220px"}
]
}
Any hint, help is really appreciated.
There can be other issues since you have not posted complete code.
First of all , I suspected there was was something off(missing css,incorrect version of kendo css referred, murtiple css conflicting) on css side since that deals with the presentation of grid .
Then i pulled up a demo and removed these css files
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.1.118/styles/kendo.common-bootstrap.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.1.118/styles/kendo.bootstrap.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.1.118/styles/kendo.bootstrap.mobile.min.css" />
and see the image below surprisingly the result are kind of little similar i can see pagination button in a vertical format.
Please double check something is off on css side(check reference to kendo grid css by looking at viewsource page) if that does not solve problem make sure you post the complete code

AngularJs component based architecture using for kendo grid

I'm very new to angular , i know little basic of angular only.
I'm trying to integrate kendo ui grid in my view using angular component.
My Angular Component :
class GetAllPostController{
constructor(API, ToastService){
'ngInject';
this.API = API;
this.ToastService = ToastService;
}
submit(){
var data = {
name: this.name,
topic: this.topic
};
this.API.all('posts').post(data).then((response) => {
this.ToastService.show('Post added successfully');
});
}
test(){
alert('');
this.gridOptions = {
sortable: true,
selectable: true,
dataSource: [
{ text: "Foo", id: 1 },
{ text: "Bar", id: 2 },
{ text: "Baz", id: 3 }
],
columns: [
{ field: "text", title: "Text" }
]
};
}
}
export const GetAllPostComponent = {
templateUrl: './views/app/components/get_all_post/get_all_post.component.html',
controller: GetAllPostController,
controllerAs: 'vm',
bindings: {},
}
My View :
<div kendo-grid k-options="gridOptions" k-ng-delay="gridOptions" ng-init="vm.test()"></div>
But it's now working. Any one please help ?
And please explain how to use scope inside componenet and view?
I'm using Laravel Angular Material
suppose u going to implement kendo inside this div
<div ng-controller="myController">
</div>
The script part
<script>
angular.controller('myController',['$scope',function($scope){
$scope.results=[];
/* ajax request and result bind to the $scope.results array */
//here you implement kendo/what ever other framework
$scope.apply(function(){
//write kendo functions inside this apply service
kendo.gridOptions = {
sortable: true,
selectable: true,
dataSource: $scope.result,
columns: [
{ field: "text", title: "Text" }
]
};
})
}])
</script>

Restangular, AngularJS and Kendo UI Grid

My problem is I'm using the kendo-grid as follows
in index.html
<table kendo-grid k-options="gridOptions" k-ng-delay="gridOptions" id="grid">
<thead>
<tr>
<th data-field="type">Type</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="asset in assets">
<td>{{asset.type}}</td>
</tr>
</tbody>
</table>
and using a factory for restangular
angular.module('myApp')
.factory('assetFactory', function (Restangular) {
return Restangular.withConfig(function(RestangularConfigurer) {
RestangularConfigurer.setBaseUrl('my/service/url');
});
});
then in assetCtrl
assetFactory.all('cases').getList().then(function(assets) {
$scope.assets = assets;
});
.......
.......
$timeout(function(){
$scope.gridOptions = {
sortable: true,
selectable: true,
scrollable: true,
groupable: true,
height:790,
pageable: {
pageSize: 25,
input: true
}
};
}, 500);
now it is working but I'm not able to add more attributes for columns or updating because everything is generated in the index.html so I feel like I have no control on it.
So I want to make it something like this
in index.html just
<kendo-grid k-options="gridOptions" k-ng-delay="gridOptions">
</kendo-grid>
and keeping the factory as it is (using Restangular)
then in assetCtrl
var myData = new kendo.data.dataSource{
data: **// assign the assets here**
}
$timeout(function(){
$scope.gridOptions = {
dataSource: myData,
columns: [
**//fields with attributes like filtering for each col**
]
sortable: true,
selectable: true,
scrollable: true,
groupable: true,
height:790,
pageable: {
pageSize: 25,
input: true
}
};
}, 500);
Also can anyone tell me how should my service return look like ?? json array or .... ?
Any help ?
Thanks in advance
I know this question is a few months old, but I had to figure out how to make Restangular and Kendo UI Grid play nice today. I eventually came across the kendo.data.DataSource api as a reference: http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read
Note: There's some solutions out there recommending using Datasource.push or DataSource.add and essentially transferring your json array via a for-loop. That's a bad idea since .add and .push both trigger an update.
Anyway, the solution using DataSource.transport.read:
Angular HTML Template:
<kendo-grid k-options="mainGridOptions"></kendo-grid>
Pertinent Controller Code:
// Set the columns of the grid. 'title' is the Label, 'field' is the corresponding json field name.
var kGridColumns = [
{title: "Asset Type", field: "asset"},
{title: "Asset Case Name", field: "name"},
{title: "Asset Case ID", field: "id"},
];
// Create a new Kendo DataSource and set the transport.read to a function.
var kDataSource = new kendo.data.DataSource({
pageSize: 10,
transport:{
read:function(e){
var assetListPromise= assetFactory.all('cases').getList();
assetListPromise.then(function(resp){
// Use .plain() to strip out all the excess Restangular features from the response
var plain = resp.plain();
// Pass your data back to the datasource/grid
e.success(plain);
});
assetListPromise.catch(function(resp){
var msg = "Issue loading asset cases:"+JSON.stringify(resp);
e.error(msg)
});
}
}
});
// Set the scope object with our columns and datasource config
$scope.mainGridOptions = {
dataSource: kDataSource,
sortable: true,
pageable: true,
columns: kGridColumns
};

Angular-Kendo TreeView with template option

I'm trying to add some icons inline to the TreeView data items, however the k-template directive does not seem to be rendering anything.
I base this off of the online docs at
http://demos.telerik.com/kendo-ui/treeview/angular
and here's a plunkr of what I'm trying to do:
treeview plunkr
My HTML (with a simple test)
<div id="treeview" kendo-tree-view="nav.treeview"
k-options="nav.treeOptions"
k-data-source="nav.reportsTreeDataSource"
k-on-change="nav.onTreeSelect(dataItem)">
<span k-template>{{dataItem.text}} TEST THIS TEMPLATE !!!</span>
</div>
and here's a snippet of my dataSource coming from my datacontext service:
function getReportsTree() {
var reportsJson = [
{
id: 1, text: "Standard", expanded: false, spriteCssClass: "rootfolder", checkChildren: true, items: [
{ id: 3, text: "MTM Aggr", reptName: "MTM Aggr", spriteCssClass: "folder" },
{ id: 4, text: "Member Aggr", reptName: "Member Aggr", spriteCssClass: "folder" }
]
},
{
id: 30, text: "Hierarchy", expanded: false, spriteCssClass: "rootfolder", checkChildren: true, items: [
{ id: 31, text: "Ctpy Hrchy", reptName: "CTPYHIER", withHierarchy: 'true' },
{ id: 32, text: "Ctpy/BkgLocation Hrchy", reptName: "CTPYHIER_BKG_LOC", withHierarchy: 'true' }
]
}
];
return $q.when(reportsJson);
}
Image showing the rendered tree, where the template does NOT render :
I need to know if I'm missing some key piece here, or do I have incorrect formatting.
thank you in advance,
Bob
**** UPDATE ****
I'm now checking to see if my Kendo UI library is a few versions behind. It may have something to do with my issue.
A Kendo UI lib update to 2014.3.1308 was necessary to get the k-template option embedded into the treeview.
However I do find a minor bug, even on their demo website - when you expand a tree node, that same level's text becomes the literal {{dataItem}}.

Resources