hello, i need to populate a GridView dynamically, i've created the colums already, but i don't know how to fill the rows???
I 've tried with Cells, but i don't find a function to put the label i want to show,
i got the following code:
tabla=new HtmlGridView(); HtmlOutputText tit=new HtmlOutputText(); tit.setValue("Monitoreo a Caja"); tabla.setHeader(tit); com.infragistics.faces.grid.component.Column col1=new com.infragistics.faces.grid.component.Column(); HtmlOutputText enc1=new HtmlOutputText(); enc1.setValue("Header 1"); col1.setHeader(enc1); tabla.getColumns().add(col1); com.infragistics.faces.grid.component.Column col2=new com.infragistics.faces.grid.component.Column(); HtmlOutputText enc2=new HtmlOutputText(); enc2.setValue("Header2"); col2.setHeader(enc2); tabla.getColumns().add(col2);
HtmlOutputText valor1=new HtmlOutputText(); valor1.setValue("valor1"); HtmlOutputText valor2=new HtmlOutputText(); valor2.setValue("valor2"); com.infragistics.faces.grid.component.RowItem ren1=new com.infragistics.faces.grid.component.RowItem(); com.infragistics.faces.grid.component.Cell cel1=new com.infragistics.faces.grid.component.Cell(); com.infragistics.faces.grid.component.Cell cel2=new com.infragistics.faces.grid.component.Cell();
HOW DO I PUT THE LABEL???????? ren1.getCells().add(cel1); ren1.getCells().add(cel2); tabla.getRows().add(ren1);
thanks.
Hello,
You have to add the labels to the cells, here are the two lines you can add to you existing code to display labels.
com.infragistics.faces.grid.component.Cell cel2=new com.infragistics.faces.grid.component.Cell();
//Add Component to the cells
cel1.getChildren().add(valor1);
cel2.getChildren().add(valor2);
ren1.getCells().add(cel1);
ren1.getCells().add(cel2);
-Taz.
Hi,
I have a similar requirement of creating the grid dynamically (both rows and columns). For this I have created a gridView binding and populating the grid in my backing bean. But unfortunately I am not getting sucess. Could you please help me in this. Basically what sould be the dataSource and how to create grid view in backing bean. If someone could share a sample code that will be very much helpful.
At runtime I get the information of number of rows and columns to be displayed. As of now I tried in the following way:
Web page:
binding="#{testBean.scorePointCalculationPointGridView}"
dataSource="#{testBean.scorePointCalculationPointDataModel}"
>
Backing Bean:
private DataModel scorePointCalculationPointDataModel;
createDynamicGrid();
}
private void createDynamicGrid(){
List tempList = new ArrayList<String>();
scorePointCalculationPointDataModel = new ListDataModel(dataModel);
HtmlOutputText tit=new HtmlOutputText();
scorePointCalculationPointGridView.setHeader(tit);
HtmlOutputText enc1=new HtmlOutputText();
col1.setHeader(enc1);
scorePointCalculationPointGridView.getColumns().add(col1);
valor1.setValue("valor1");
scorePointCalculationPointGridView.getRows().add(ren1);
When I am executing this then I am not getting the rows displayed. Only the heading of the column and a blank row.
Thank you
Kaushal
My first advice would be to have a look at our example on Dynamic Grid at our NetAdvantage for JSF Samples site. There you can find a working example demonstrating a Dynamic Grid under WebGrid/Dynamic Grid. The source is available in the INSTALL_FOLDER/demos/src/main/... folder on your computer. If after this there are still any questions do not hesitate to ask for help.
Regards!
Hi!
Here I will post a simplified example that emphasizes on the dynamic column creating.
In JSF:
<ig:gridView id="grid1" dataSource="#{dynGrid.dataSource}" binding="#{dynGrid.grid}">
In Java:
public GridView getGrid() {
this.grid = grid;
// if the grid is empty, it probably means that it hasn't been
// initialized yet
initGrid();
FacesContext context = FacesContext.getCurrentInstance();
// clear the grid
clearGrid();
// set the pagesize
"#{DATA_ROW.firstName}", "firstName");
"#{DATA_ROW.lastName}", "lastName");
"email");
"#{DATA_ROW.phoneNumber}", "phoneNumber");
// ask the grid to rebind itself to its datasource
grid.setHeader(null);
grid.getTemplateItems().clear();
String binding, String sortByCriteria) {
columnHeader.setValue(header);
column.setHeader(columnHeader);
// define the value binding
.createValueBinding(binding));
column.getChildren().add(columnContent);
// if there is a sortby criteria
column.setSortBy(sortByCriteria);
dataSource = new ArrayList();
"555-1234");
person = new Person("Karin", "Rolfson", "K.Rolfson@mymail.com",
private String firstName = null;
private String email = null;
String phoneNumber) {
this.lastName = lastName;
...
// Getters and Setters
Can you provide a more complex create column example that allows dynamically adding an editable column containing dropdown in WebGrid.
The static jsf code is something like this:
Try with calling that method instead of the createColumn method in initGrid(). It is used the same way like createColumn() and adds an Infragistics DropDownList to the column.
String header, String binding, String sortByCriteria) {
dropDown.setDataSource(dropDownSource);
column.getChildren().add(dropDown);
private List createSelectionList() {
result.add(new SelectItem("United States"));
result.add(new SelectItem("United Kingdom"));
I hope this will help you!
Thanks for your reply!! A related question though:
How can I set this dynamic grid as "editable" programatically. The idea is that once these UIInput components(dropdowns) nested within the columns are edited, the underlying data model is also updated automatically.
Basically, its could be like adding the tag <ig:gridEditing /> to the grid from code.
Thanks and Regards!
The behavior you've described doesn't seem to be right, based on what I'm seeing. So that we can investigate this in more detail, and provide you with a fix once one becomes available, please submit a support request to Infragistics Developer Support. You can provide the URL of this thread in your support request, so that we know the two are related.
Are you just informing that there is no solution at present ?
Here is what I tried:
com.infragistics.faces.grid.component.html.HtmlColumn aColumn = (com.infragistics.faces.grid.component.html.HtmlColumn)application.createComponent(com.infragistics.faces.grid.component.html.HtmlColumn.COMPONENT_TYPE);HtmlColumnSelectRow col1Value = (HtmlColumnSelectRow) application.createComponent(HtmlColumnSelectRow.COMPONENT_TYPE);col1Value.setShowSelectAll(true);aColumn.setHeader(col1Value);aColumn.getChildren().add(col1Value);grid.getTemplateItems().add(aColumn);
This adds a column with checkbox option to select a row, grid.getSelectedRows() function works fine in bean.
However, the checkbox that should appear in header row to allow selection of all rows when selected, does not appear.
Can you suggest how to make the header row checkbox appear and work?
Regards
You could turn to that thread. I suppose the situation is very similar.
Thanks!
I need a dynamically created grid where the first column should allow row selection. This should be equivalent to adding <ig:columnSelectRow showSelectAll="true" /> tag to the grid. How can this be added programatically ?
This tag if inserted statically to jsp page does not work after columns are added at run time:
<ig:gridView id="grid1" dataSource="#{dynGrid.dataSource}" binding="#{dynGrid.grid}"> <ig:columnSelectRow showSelectAll="true" /> </ig:gridView>
regards,
When you call the createColumnWithDropDown() method with the appropriate parameters, i.g.
Column column5 = createColumnWithDropDown(context, "Country", "#{DATA_ROW.country}", null);
then you bind the specified binding (in this case #{DATA_ROW.country} ) to the value property of the DropDown:
So you don't need to do anything else, the underlying data model is being updated with the selected value from the DropDownList automatically.