I am trying to divide a Row into two ie. Row Span in Angular JS UI Grid. I am not able to find how to do this.I need different color schemes for rows within the rows of the UI grid. Can anyone please help me with this and give me some related fiddle or plunker to refer. Thanks in advance.
I have a RowSpan hack, suitable for my need, not necessarily suitable for every case: I use position:absolute on the top row's cell and display:none on the spanned rows' cells. See http://plnkr.co/edit/TiQFJnyOvVECOH2RL4ha
Everything is in the ng-style in the cell template, which uses a spanCompany attribute to know the number of rows to override. We have to calculate the height and width since we are position:absolute. This also means the width has to be expressed in px, not %.
ng-style extract:
ng-style="{
height:21*row.entity.spanCompany+'px',
width:col.width+'px',
position:'absolute',
display:row.entity.spanCompany==0?'none':'block'
}"
Full code:
var app = angular.module('app', ['ngTouch', 'ui.grid']);
app.controller('MainCtrl', ['$scope', function ($scope) {
$scope.data = [
{
"firstName": "Cox",
"lastName": "Carney",
"company": "Enormo has a rather long company name that might need to be displayed in a tooltip",
"spanCompany":2,
"employed": true
},
{
"firstName": "Lorraine",
"lastName": "Wise",
"company": "Enormo",
"spanCompany":0,
"employed": false
},
{
"firstName": "Nancy",
"lastName": "Waters",
"company": "Fuelton",
"spanCompany":1,
"employed": false
}
];
$scope.gridOptions = {
columnDefs: [
{ name: 'firstName', width: '20%' },
{ name: 'lastName', width: '20%' },
{ name: 'company', width: '200',
cellTemplate: '<div class="ui-grid-cell-contents wrap" title="TOOLTIP" ng-style="{ height:21*row.entity.spanCompany + \'px\', width:col.width+\'px\', position:\'absolute\', display:row.entity.spanCompany==0?\'none\':\'block\', borderStyle:\'dotted\', borderWidth:\'1px\'}" >{{COL_FIELD CUSTOM_FILTERS}}</div>'
},
{ name: 'employed', width: '30%' }
],
data: 'data',
rowHeight: 21
};
}]);
Related
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>
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.
I am trying to use multiple select in anguler-ui-grid but get error:
TypeError: value.forEach is not a function
at writeNgOptionsMultiple [as writeValue] (angular.js:26579)
at ngModelCtrl.$render (angular.js:28680)
at Object.ngModelWatch (angular.js:25493)
at Scope.$digest (angular.js:15888)
at angular.js:16091
at completeOutstandingRequest (angular.js:5552)
at angular.js:5829(anonymous function) # angular.js:12520(anonymous function) # angular.js:9292Scope.$digest #
angular.js:15914(anonymous function) #
angular.js:16091completeOutstandingRequest # angular.js:5552(anonymous
function) # angular.js:5829
Here is the code: The only change from the official template is the "multiple" attribute in the dropdown template tpl
var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.edit']);
app.controller('MainCtrl', ['$scope', function ($scope) {
var myData = [
{
"firstName": "Cox",
"lastName": "Carney",
"employed": true
},
{
"firstName": "Lorraine",
"lastName": "Wise",
"employed": false
},
{
"firstName": "Nancy",
"lastName": "Waters",
"employed": false
}
];
var dropDownArray = [
{ id: 'Gabi', firstName: 'Gabi' },
{ id: 'Gabriel', firstName: 'Gabriel' }];
$scope.msg = "hello shit";
var tpl = '<div>\
<form\
name="inputForm">\
<select multiple\
ng-class="\'colt\' + col.uid"\
ui-grid-edit-dropdown\
ng-model="MODEL_COL_FIELD"\
ng-options="field[editDropdownIdLabel] as field[editDropdownValueLabel] CUSTOM_FILTERS for field in editDropdownOptionsArray">\
</select>\
</form>\
</div>';
$scope.gridOptions = { data: myData,
columnDefs: [{ field: 'firstName', displayName: 'First Name', width: 190,
editableCellTemplate: tpl,
editDropdownValueLabel: 'firstName',
editDropdownOptionsArray: dropDownArray },
{ field: 'lastName', displayName: 'Last Name', width: 180 },
{ field: 'employed', displayName: 'employed?', width: 180 }]}
}]);
I ran into the same problem - a tough one because it works with angular 1.2 but not with 1.4.
The solution for me was that the initial field value has to be an array, not a string.
So your data must look like this:
var myData = [
{
"firstName": ["Cox"],
"lastName": "Carney",
"employed": true
},
{
"firstName": ["Lorraine"],
"lastName": "Wise",
"employed": false
},
{
"firstName": ["Nancy"],
"lastName": "Waters",
"employed": false
}
];
And the error should go away.
maybe the title of my question is not proper, please feel free to update my title.
my json data is like
[
{ "AutoId": 2, "CustomerId": "1000AIRLIESST", "customerLastName": "John", "locationId": "2", "Address": "1000 AIRLIES ST Winnipeg " },
{ "AutoId": 2, "CustomerId": "1000AIRLIESST", "customerLastName": "John", "locationId": "186471", "Address": "1000 Airlies ST Winnipeg " },
{ "AutoId": 2, "CustomerId": "1000AIRLIESST", "customerLastName": "John", "locationId": "186752", "Address": "111 pineview rd ST Winnipeg " }
];
as you can see the autoId, customerId and lastname are same. I want to demonstrate this data in ui-grid like following picture. I want to common part of my data comes in main columns.
It is impossible to group two column with same grouping priority
groupPriorities should generally be sequential, if they're not then the next time getGrouping is called we'll renumber them to be sequential.
Defaults to undefined.
so my solution is like a cheat. first I use the aggregation function (max) for second column (customerLastname). then I used a custom directive to manipulate data.
you can see the result in plunker
The column definition of ui-grid
$scope.gridOptions = {
enableFiltering: true,
treeRowHeaderAlwaysVisible: false,
columnDefs: [
{
name: 'customerLastName',
displayName: 'Customer LastName',
width: 200,
treeAggregationType: uiGridGroupingConstants.aggregation.MAX,
cellTemplate: '<div class="ui-grid-cell-contents" > <fakemax val="{{COL_FIELD}}" /></div>'
},
{
name: 'Address',
width: 200,
},
{
name: 'CustomerId',
grouping: { groupPriority: 0 },
sort: { priority: 0, direction: 'desc' },
width: 200,
cellTemplate: '<div><div ng-if="!col.grouping || col.grouping.groupPriority === undefined || col.grouping.groupPriority === null ||' +
' ( row.groupHeader && col.grouping.groupPriority === row.treeLevel )" class="ui-grid-cell-contents" title="TOOLTIP">{{COL_FIELD CUSTOM_FILTERS}}</div></div>'
},
],
data: 'Customers',
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
}
};
please pay attention to fakemax directive which I used in the cellTemplate of customerLastName. the custom directive is so simple.
app.directive('fakemax', function () {
return function(scope, iElement, iAttrs) {
var value = iAttrs.val;
value = value.replace("max:", "");
iElement[0].innerHTML = value;
}
});
I have looked around but I still don't understand how to create treestore properly.
I have this very simple json that I get from a server:
{
"Results": [
{
"name": "John",
"age": 23,
"cars": [
{
"name": "Clio",
"brand": "Renault"
},
{
"name": "Class S",
"brand": "Mercedes"
}
]
},
{
"name": "Michel",
"age": 42,
"cars": [
{
"name": "Qashqai",
"brand": "Nissan"
}
]
}
]
}
I have my two models:
Ext.define('Person', {
extend: 'Ext.data.Model',
fields: [ 'name', 'age']
});
Ext.define('Car', {
extend: 'Ext.data.Model',
fields: [ 'name', 'brand']
});
Now I know that I have to create a tree store, but in all example that I have seen, there is always a "children" property in the json, which I don't have.
How to create a tree store with the following json?
Thanks a lot in advance :) !!
You could always build the correct formatted object for the data like the following:
Ext.application({
name: 'Fiddle',
launch: function () {
var myTreeData = {
"Results": [{
"name": "John",
"age": 23,
"cars": [{
"name": "Clio",
"brand": "Renault"
}, {
"name": "Class S",
"brand": "Mercedes"
}]
}, {
"name": "Michel",
"age": 42,
"cars": [{
"name": "Qashqai",
"brand": "Nissan"
}]
}]
},
modifiedData = {
expanded: true,
children: []
};
myTreeData.Results.forEach(function (result) {
var newChildrenArray = [];
result.cars.forEach(function (car) {
var newChild = {
text: car.name,
leaf: true
};
newChildrenArray.push(newChild);
});
var person = {
text: result.name,
leaf: (newChildrenArray.length > 0 ? false : true),
children: newChildrenArray
};
modifiedData.children.push(person);
});
var store = Ext.create('Ext.data.TreeStore', {
root: modifiedData
});
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});
}
});
Demo here: https://fiddle.sencha.com/#fiddle/j05