Extjs 4. How to parse grid store and change cell background dynamically? - extjs

I have a grid, in which some rows with data are "inherited". That is, there are some parent rows and child rows. Child rows have the id_inherit field set to the id of the parent row. The grid is editable. Now I want to add some functionality which makes it possible to analyze changes in all child rows. If some value in some cell is different from that in the parent row, then I want to change the background of that particular cell in the inherited row. I want to do these analytics on the fly: in other words, I want to make it when the user hits the button. Now, I parse my grid rows like this:
var store = Ext.getCmp('grid').getStore();
store.each(function(record,idx){
if(record.get('id_inherit')!=0){ // grid row is inherited
// here I want to compare values in all cells of this row
// and the parent row, whose `id` is equal to record.get('id_inherit')
// if values are different in a particular cell of the inherited row, then
// I want to change its background color
}
});
EDIT
Now, without any comparison, I just try to change the cell color of all inherited rows, but it does not work. I do it like this:
store.each(function(record,idx){
if(record.get('id_inherit')!=0){
grid.getView().addRowCls(idx,'red');
// I guess I should have used addCls instead, but
// I do not know how to target a particular cell inside this record
// and change its class correctly
// but of course, I know column names and indices
}
});
And red style is defined like this:
.red {background-color: red !important;}
But it is not working. If I knew how to change the cell color dynamically, I could do all the other routines - comparing with parent rows, etc.
EDIT
I tried practically all solutions posted at StackOverflow and which seem to relate to some extent to my problem, but none of them work. What I want to stress again, is that I need to change the background color of a particular cell - NOT of the entire row and NOT of the entire column. And I want to do it on the button click - NOT inside the render function.
EDIT
I consulted this article ExtJS 4 Grid Change Cell Color , but the author manupulates the DOM of the selected row, and does it like this:
var selection = grid.getView().getSelectionModel().getSelection()[0];
var dom = (grid.getView().getSelectedNodes()[0]);
tds = Ext.get(dom).select("div");
Ext.get(tds.elements[evt.target.offsetParent.cellIndex]).addCls('black');
But in my case, where I iterate through the grid store, I do not know how to get to the dom of the current record, then select the div and add a custom class.
EDIT
Well, I tried thousands of tricks, but nothing works at all. If someone could advise me on how to parse a grid record to get to the cell HTML-structure, I would mark this advice as an answer. What I now know, inspecting the DOM structure, is, for example, that one of my cells has this CSS class x-grid-cell x-grid-cell-73892 x-grid-cell-last. What makes it unique is this part: x-grid-cell-73892. So, I tried to do it this way
store.each(function(record,idx){
var div = Ext.fly(record).query('x-grid-cell-73892').select('div')
....
});
But this is not working. Who would have thought, that such a trivial thing - the most trivial that I can imagine - that is to change the background color of a cell on button click, has no simple solution. At this point I have no solution, in fact.
EDIT
Well, I did it myself. The trick was to use the getCell function:
var column=grid.columns[index],
cell=grid.getView().getCell(record, column);
cell.addCls('mycss');

Related

Change the row height dynamically using react-data-grid

I am using react-data-grid library.
2nd column's first row content is
'It is a long text, though it is not displaying the whole content. as a solution, I want to change the row height dynamically'
So how can I change the row height dynamically?
rowHeight won't work in my case
likewise, permission group column also has many labels like pg3, pg4. there also only one label is appearing.

How to set grid column title in dynamic way without using refresh function

I got requirement to set column title per condition.
No Grid method allows me to set column title after table gets rendered.
I tried with setting new title via manipulating its value in options.
But after that, I'll need to call refresh() method to show my new title.
Because in the grid, I always have some columns hidden dynamically.
Refresh() method will make these hidden columns showing again on the screen and I don't want it.
So, is there a way to set new value to column title?
Thanks.
For hiding individual columns, you can use the hideColumn, showColumn and isHidden methods.
You can also use the visible column property to set column visibility at initialization time.
There is no setTitle() method currently implemented, but you can email Shield UI's support and ask them to implement that for you. Depending on their load, they might do it real quick.
Until that is implemented, you can always update the title by using jQuery.

uiGrid switch rows and columns

This is a bit of a general question into the possibilities of ui grid. I have had tremendous success with ui grid thus far. Now I have a use case where I want to switch the rows and columns of the grid.
Basically, I would like the headers to be displayed 'vertically' in the first column and to have the rows become columns.
Is this possible with ui grid?
As far as i know UI-grid doesn't support this. I doubt if you can do that. May be try building ColumnsDef and Data dynamically and pass it to gridOptions. Or else add extra column and this should be the first column where you will pass all the header values. Change the background of the cells to look like header cells. Now add second column where you pass the entire first row values. Hide the original header row completely. see now u got your required grid........ :)

How to get ng-grid to hide certain rows

I have an array of objects that I want to show in ng-grid. Each row has a boolean property isVisible. In the ng-grid I want to show only the rows where isVisible is true. The other rows should be completely hidden.
I have tried using a rowTemplate and databinding a ng-show to isVisible. That hides the content of the row, but leaves the actual row in place, showing an empty row.
I have tried using filterOptions, but can't figure out the correct syntax to do such a filtering. I couldn't find any good documentation on how to set it.
I have even tried modifying the gridTemplate in the ng-grid source, by trying to add a filter on ng-repeat=\"row in renderedRows\", but I haven't gotten that to work either.
I guess I could modify the array itself, by temporarily removing rows, but I would prefer not to do it that way, since I have to be able to show the rows again (It is actually an expander that I'm doing, that should hide/show sub-rows)
Try also conditionally setting the height of the row in the template to '0' based on isVisible or use a CSS class with ng-class. Play with the CSS of it until you get the desired effect and then you can use that in your template.
This sounds like the type of thing that would benefit from using height and CSS animations actually so it opens and closes with an animated style. If you have a jsFiddle sample I'd be happy to try and help.
Edit: After looking at how the grid actually lays out it's rows (absolutely positioned) you only really have two options I can think of:
1) Filter the data you are binding to the grid through a function like dataVisible() but keep the full data list internally in the controller so you can show/hide easily
2) Submit a patch to the ng-grid project (or fork it) with the filtering capability you are looking for. Out of the box it doesn't appear to support this scenario.

Grid not updating upon change in model in angularjs

Folks,
I am using ng-grid to display a list of items.
I want to give my users ability to rearrange the rows in the list.
i.e move the rows up and down as they please.
Now,
However when I update the grid data in the backend i.e say change the index of a particular row, that row does not automatically change locations in the front-end.
What am i missing here ?
I have created a plunker to describe the problem
http://plnkr.co/edit/s1hrTSqF2zeZo3Btaln0
The grid doesn't use the index of the array to order it, so even if you are changing it, because the data is still there nothing happens.
What you could do is define an order field and update the value then changing the values as shown in this plukr. The order field you can hide it from the grid if required using columnDefs to explicitly defined which column should be shown.
Regards

Resources