How do I find matching subGridOptions.data element for expanded row? - angularjs

In Angular UI-Grid v4.0.4, I have a button called "ViewLog" for each row that's inside an expandable row. I'm trying to display the data that's inside the child row when the ViewLog button is clicked.
This is the structure
Parent Row 1
|
--- (ViewLog) Child 1 (json for child 1)
--- (ViewLog) Child 2 (json for child 2)
--- (ViewLog) Child 3 ...
|
Parent Row 2
|
--- (ViewLog) Child 1 (json for child 1)
--- (ViewLog) Child 2 ...
The code for expandable:
gridApi.expandable.on.rowExpandedStateChanged($scope, function (row) {
if (row.isExpanded) {
row.entity.subGridOptions = {
appScopeProvider: $scope,
columnDefs: [
{
name: 'Log',
field: '',
width: "85",
cellTemplate: '<button ng-click="grid.appScope.displayLogFile(row.entity.subGridOptions.data[howToFindRightElement]);">View Log</button>'
}
]
};
}
});
In my example above, in cellTemplate, row.entity.subGridOptions.data is an array. I can't seem to figure out how to identify the correct element from that array that matches the child row selected after expanding the Parent row.
I just want to find the JSON from the child row and pass it over to displayLogFile().

So if I understand you correctly, you want to see the data of a newly generated ui grid that is created after expanding the row. If that is the case, then I think you need to treat is as another scope. The row.entity in expandable !== row.entity in cellTemplate. That being the case, then all you should need is this row.entity. So the following columnDef setup should work.
row.entity.subGridOptions = {
appScopeProvider: $scope,
columnDefs: [
{
name: 'Log',
field: '',
width: "85",
cellTemplate: '<button ng-click="grid.appScope.displayLogFile(row.entity);">View Log</button>'
}
]
};

Related

Extjs: Remove child tags from tagfield when parent tag is removed

I have two tag fields.
1-Parent tag
2-Child tag
Parent tag includes 5 categories i.e a,b,c,d,e
Child tag includes the corresponding tags from parent
Ex- If a user selects parent tag 'a'(or a,b,c) or selects any tag then everytime a function is called then a store service is called which loads all the corresponding child tags by passing extraparam(a in case one single tag selection and comma seperated parameters in case of multi-select) to the in child tagfield.
So child tagfield is then loaded with the corresponding dropdown according to the selections made in parent tag and user can add the corresponding tags to the child tagfield.
Now, I want to remove the corresponding child tags if a parent tag is removed.
Ex- If user selects a and its corresponding entries are x,y,z.
So if a user adds x and z in the child tagfield.then if he removes parent tag i.e 'a' then x,y should also get removed from the child tagfield which were added.
Tagfield code:
{
fieldLabel: 'FieldA',
displayField: 'Label',
itemId:'FieldA',
valueField: 'Type',
listeners:{
change: 'selectedFieldATypes'
},
bind: {
store: '{FieldATypes}',
hidden: '{status === "NULL"}'
},
},{
fieldLabel: 'FieldB',
itemId:'FieldB',
displayField: 'label',
valueField: 'name',
editable: true,
selectOnFocus: false,
listeners:{
render: 'FieldATypes'
},
bind: {
store: '{FieldBStore}',
hidden: '{status === "NULL"}'
},
}
Function code:
selectedFieldATypes: function(){
const viewModel = this.getViewModel();
viewModel.set('selectedtypesarray',selectedTypes);
selectedTypes=Ext.ComponentQuery.query('#FieldB').getValue();
if(selectedTypes.length==0){
this.getStore('FieldBStore').load({params: {Ids:[Comma seperated ID's of selected Parent tag]}});
}
else{
this.getStore('FieldBStore').load({params: {groupIds:All id's if not parent tag is selected}})
}
},
Set field Value to null
selectedFieldATypes: function(fldA, newValue, oldValue){
if(Ext.isEmpty(newValue)) {
// get reference of field B and set the Value to null
fldA.next().setValue(null);
// clear fieldB store
// fieldBReference.getStore().removeAll();
return;
}
// your Code
}

Angular Ui-Grid Multi Level Nesting

I am using Angular Ui-grid.Trying to achieve multi level nesting in that. Some one have already raised the issue in uiGrid github. But that solution doesn't seems working.
I have changed the JSON like this. I am trying to form nested sub grid.
Below is my code
$scope.gridOptions = {
expandableRowTemplate: 'expandableRowTemplate.html',
enableGridMenu: true,
expandableRowHeight: 150,
paginationPageSizes: [5, 10, 15],
paginationPageSize: 5,
//subGridVariable will be available in subGrid scope
expandableRowScope: {
subGridVariable: 'subGridScopeVariable'
}
}
$scope.gridOptions.columnDefs = [
{ name: 'id', enableHiding: false },
{ name: 'name' },
{ name: 'age' },
{ name: 'address.city' }
];
$http.get('http://private-7a7085-getfriends1.apiary-mock.com/getfriends')
.success(function (data) {
for (i = 0; i < data.length; i++) {
//for(i = 0; i < 50; i++){
data[i].subGridOptions = {
columnDefs: [{ name: "Id", field: "id" }, { name: "Name", field: "name" }, { name: "Age", field: "id" }, { name: "Address", field: "name" }],
data: data[i].friends,
expandableRowTemplate: 'expandableRowTemplate1.html',
enableGridMenu: true,
expandableRowHeight: 150
}
for (j = 0; j < data[i].friends.length; j++) {
data[i].subNestedGridOptions = {
columnDefs: [{ name: "Id", field: "id" }, { name: "Name", field: "name" }, { name: "Age", field: "id" }, { name: "Address", field: "name" }],
data: data[i].friends[j].friends
}
}
}
$scope.gridOptions.data = data;
});
and second level nested html(expandableRowTemplate1.html) looks like
<div ui-grid="row.entity.subNestedGridOptions" style="height:150px;"></div>
When I pass data to ui-grid for second level nested grid, it throws undefined.
Does any one have success till now to implement Expandable UI Grid with more then 2 or 3 levels. If yes please share plunker or fiddle or detailed explanation would be really helpful!
I have this working now. I assume you have constructed the proper data to bind at 3 levels. I assume that you have a 2 level grid working as well (parent grid's rows expand to show child grids). Here are the key few pieces I added to get this to work:
The top level grid has the directive ui-grid-expandable in the div tag that defines it. This is located in my html view.
<div ui-grid="gridThreeLayer" ui-grid-expandable></div>
The top level grid defines an expandableRowTemplate in its gridOptions (angularJS) .
$scope.gridThreeLayer = { ........
expandableRowTemplate: '..your path.../expandableRowTemplate.html' }
The top level grid's expandableRowTemplate will contain a div tag that defines another "ui-grid" and has the directive "ui-grid-expandable".
<div ui-grid="row.entity.subGridOptions" ui-grid-expandable></div>
The 2nd level grid has its subGridOptions and columnDefs built on the fly when the data is being bound in the angularJS (off an $http.get() for me). At this time, you need to specify an expandableRowTemplate property on that 2nd level grid which tells it to expand and show the 3rd level grid.
for (i = 0; i < response.data.length; i++) {
response.data[i].subGridOptions = { .....
columnDefs: [ ............],
data: response.data[i].IP, // note that this is my 2nd level of data objects - yours will differ
expandableRowTemplate: 'AngularApp/Templates/MultiLevelTemplate.html
The expandableRowTemplate of the 2nd level grid needs to define a div tag with a "ui-grid", instructing the grid to render a nested grid for each row. It does NOT need a directive for expanding (but you could add one to go 4 levels deep). Mine is called MultiLevelTemplate .
<div ui-grid="row.entity.subGridOptions"></div>
Now in the same angularJS block, where you are building each row's gridOptions and columnDefs on the fly, you need to go to another level of iterations through that level of the data. This will allow you to define the subGridOptions and columnDefs fo the 3rd level grid. So you are in the "i" loop, and starting an "x" loop within it. Note that in setting the data source, it is using my own 3 levels of data objects. You need to use your own there.
for (x = 0; x < response.data[i].IP.length; x++) {
response.data[i].IP[x].subGridOptions = {
columnDefs: [........],
response.data[i].IP[x].subGridOptions.data = response.data[i].IP[x].BOM; // my data
If you do all of the above, it should work correctly if your data is set up correctly.

How to change particular row wise column value in angularjs ui grid?

I need to change the value in a particular row wise column value in ui grid i.e., from Inactive to active status
I have a table in ui grid like
ID Name Status
1 India Active
2 Germany Inactive
3 France Active
4 Italy Active
5 Canada Inactive
My grid code
$scope.gridOptions = {
columnDefs: [
{
field : 'name',
displayName : 'Name',
width : '25%',
enableColumnMenu : false,
sort : {
direction : uiGridConstants.ASC
},
cellTemplate : '<div class="ngCellText" ng-class="col.colIndex()" ng-controller="NameController"><a ng-click="editPop({{row.entity}})">{{COL_FIELD}}</a></div>'
}, {
field : 'status',
displayName : 'Status',
width : '25%',
enableColumnMenu : false,
cellTemplate: '<div ng-controller="StatusController" ng-if=\"row.entity.status == \'Active\'\" ><img src=\'assets/img/on.png\' /><a ng-click="checkStatusDepend(row.entity.id,row.entity.name,row.entity.status)">Active</a></div>'+
'<div ng-controller="StatusController" ng-if=\"row.entity.status == \'Inactive\'\" ><img src=\'assets/img/off.png\' /><a ng-click="checkStatusDepend(row.entity.id,row.entity.name,row.entity.status)">Inactive</a></div>'
}
],
data: 'myData'
};
For calling this grid
getPage();
var getPage = function(obj) {
object.charge({}, function(list){
$scope.myData = list.data;
});
};
I am getting the list in myData so it is displayed in ui grid table.
I am updating the status in status controller
$rootScope.$emit("statusUpdateCall",id);
and for changing the value in another controller
$rootScope.$on('statusUpdateCall', function(events, args){
getPage();
});
I want to change for ID no 2 status Inactive to Active, in backend using rest spring i am updating in database but in frontend i need to change it to Active.
Currently i load the data from beginning.
I have gone through the angularjs ui grid tutorial using splice it removes particular row and add a new row with new changed data.
But without splice is there any other options are there to update particular column value?

kendo TreeList: sort columns based on parent element only?

Here is an example kendo treeList. How can i sort the data in the treeList, depending on values based only on parent element?
In the example, if i sort the data on column 'P names', the child elements are also sorted. How can i sort only parent elements?
Thanks in advance.
You just need to add custom comparer for column.
Look in kendo Docs
In your case it will look like this:
$("#grid").kendoGrid({
dataSource: dataSource,
sortable: true,
columns: [{
field: "item",
sortable: {
compare: function(a, b) {
if(a.level>1){
var dataRows = $scope.grid.items();
var ARowIndex = dataRows.index(a);
var BRowIndex = dataRows.index(b);
return ARowIndex > BRowIndex ;
}
else
return a.item> b.item;
}
}
}]
});

Kendo grid with dropdown action command

I have a KendoUI Grid bound using Angular and I'd like to implement a custom action dropdown command or template column on each row. I need to track the dropdown change event for any of the rows when the grid is in display mode, not edit mode. The dropdown is effectively just a list of all of the name properties of the grid rows that I want to user to be able to select to move the row after another existing row.
For instance, say I have this data:
Id Name Position
A Red 1
B Blue 2
C White 3
I'd like each row to display a dropdown column while in display mode (so it acts like a row command). The dropdown would contain the names Red,Blue,White with corresponding values. When a user picks one of those colors, I will change the position of that row to the row position after the color selected. It's basically a row reorder dropdown instead of using drag and drop.
My other option is to show a couple of template columns with a move up/move down metaphor to do the switch but that gets a little cumbersome when you want to move a row more than a couple of positions.
Any ideas?
Ok, I did some more searching and found out a way to do this although it's not 100% of the way there yet. I also found a way to bind the dropdown to the data that populates the grid
The other thing I found when doing it this way is it is painfully slow in rendering the grid now.
<div id="mainGrid" kendo-grid="mainGrid" k-options="mainGridOptions"></div>
//grid columns
$scope.mainGridOptions = {
dataSource: {
transport: {
read: function (e) {
gridcolumnService.getGridColumns().success(function (data) {
e.success(data);
});
},
},
},
columns: [
{ field: "Name" },
{ field: "ColumnSettings.Type", title: "Type" },
{ field: "ColumnSettings.PrimaryKey", title: "Primary Key", template: '<input type="checkbox" #= ColumnSettings.PrimaryKey ? "checked=checked" : "" # disabled="disabled" ></input>' },
{ field: "ColumnSettings.Title", title: "Title" },
{ field: "ColumnSettings.Editable", title: "Editable", template: '<input type="checkbox" #= ColumnSettings.Editable ? "checked=checked" : "" # disabled="disabled" ></input>' },
{ field: "ColumnSettings.Visible", title: "Visible", template: '<input type="checkbox" #= ColumnSettings.Visible ? "checked=checked" : "" # disabled="disabled" ></input>' },
{ field: "LookupDataCommandId", title: "Lookup", template: '#= LookupDataCommandId ? "Yes" : "" #' },
{ template: '<select id="reorder-dropdown" kendo-drop-down-list k-on-change="exchangeRows(dataItem, kendoEvent)" k-data-source="reorderData()" k-data-text-field="\'Name\'" k-data-value-field="\'GridColumnId\'"></select>' },
{ template: '<a kendo-button k-icon="\'pencil\'" ng-click="editGridColumn(dataItem.GridColumnId)">Edit</a>', width: 100 }
]
};
$scope.reorderData = function() {
return $scope.mainGrid.dataSource.data();
};
$scope.exchangeRows = function (fromRow, e) {
$log.log(fromRow.GridColumnId, e.sender.dataItem().GridColumnId);
};

Resources