How to create a dynamic(programatically) webgrid editable.
Hello Goutam, In order to apply gridEditing feature for Dynamic WebGrid, please include below code snippet in initGrid() method in backing bean.
grid.getTemplateItemsBehaviors().getFacets().put(GridView.FACET_GRID_EDITING, new HtmlGridEditing());
Thank you!
Swetha
How to add CellValueChangeListener on dynamic webgrid code snipplet mentioned above?
Hello Gautam,
Its simple...
You need to create the instance of HtmlGridEditing and use the methodbinding expression for this where you declear the event handler name. After creating this HtmlGridEditing object, you add this object to the template behavior as the Swetha suggested..
Hope it helps you.
Roshan
Yes it is , I was following the same steps defined by you.
Can you please provide me the syntax for the same?
I got stuck there.
Can some one provide me some lines of code to define the
CellValueChangeListener dynamically? I am looking for sample code snipplet.
Here is the code snippets for you:
...HtmlGridEditing editing = new HtmlGridEditing();MethodBinding mb= application.createMethodBinding("#{GridBean.cellValueChange}", new Class[]{CellValueChangeEvent.class});editing.setCellValueChangeListener(mb); grid.getTemplateItemsBehaviors().getFacets().put(GridView.FACET_GRID_EDITING, editing);....public void cellValueChange(CellValueChangeEvent evt){ System.out.println("Vlaue Has been Changes");}
Thanks Roshan. Yes it helped a lot.
Can you please let me know how to chnage the background colour of the column dynamically?
I used following code snipplet for doing the same:
Column basicColumn =
new Column();
basicColumn.setSortBy(
"basic" );
//Column Cell Style
UnifiedValueExpression uniValueExpressionColumnStyle = UnificationHelper.createUnifiedValueExpression(
basicColumn.setUnifiedValueBLOCKED EXPRESSION
{}
But it didn't work.
Please provide me code snipplet for setting the coloum background colour dynamically.
Hello , Goutam
Do you want to set the color in the row you have selected?
Is this what you mean ?
I understand that you want to set different color of each row by what you have said.
If you want this there is a way (the source code below is in the context of the snippet.txt)
editGrid
.setRowStyleClass("igGridRow"); // igGridRow is styleClass defines in igf_grid.css
editGrid.setRowAlternateStyleClass("igGridRowAlternate"); // igGridRowAlternate - styleClass
Keep in mind to define igGridRow and igGridRowAlternate in the igf_grid.css file inside the Theme
you are using :
.igGridRow
{background-color: #888888;}
.igGridRowAlternate
{background-color: #F5F5F5;}
I hope this helps!
Please let me know how can you retrieve the data from DATA_ROW and set the same in the following inside you java code:HtmlColumn firstNameColumn = new HtmlColumn ();firstNameColumn.setStyle("background-color: #AACC44;");
What i mean to say that the colour is set in the DATA_ROW object.During the creation of the table that should get pickedup and set in the column.How can it be possible to get the value from DATA_ROW in the java code?
The snipped is in the attached file.
Hi Gautam,
Here are some code snippets for you. The bolded text is about the background colour
I hope they will help you
public void initEditGrid() {
FacesContext context = FacesContext.getCurrentInstance();
clearGrid();
HtmlGridEditing gridEditing = new HtmlGridEditing();
Class[] args = new Class[] { CellValueChangeEvent.class };
UnifiedMethodExpression methodExpr = UnificationHelper
.createUnifiedMethodBLOCKED EXPRESSION;
}