Hi, haven't done this in a while, so hoping for some help.
I have a DataSource with a foreign key field:
I have a ListGrid with a field using the optiondatasource setup:
When I set a cell formatter on that field, the "value" is the value of the "name" attribute as defined in the related optiondatasource record.
Now, my use case is this - I want to search the grid for records that have a "name" attribute in the optiondatasource that corresponds to a search string entered by the user in a popup window..
If I do grid.getRecords() and check the contractorId, they are of course just the foreign key ID values to a record in the contractor datasource. So how do I traverse over to the contractor datasource to compare the name value there while iterating the rows in the list grid?
If I am confused, please let me know - again, hoping for help and tips.
I have a DataSource with a foreign key field:
I have a ListGrid with a field using the optiondatasource setup:
Code:
<field name="contractorId" type="integer" foreignKey="contractor.id" displayField="name" required="false"> <title> <fmt:message key="contractorId"/> </title> </field>
Code:
public class FKGridField extends ListGridField { public FKGridField(DataSource owningDataSource, DataSourceField dataSourceField, String optionOperationId) { setName(dataSourceField.getName()); //this is a punctuation-separated string that specified the datasource and primary key field of the datasource used by this combobox. For exmaple "location.id" String[] foreignKeyElements = FormUtils.getForeignKeyElements(dataSourceField.getForeignKey()); DataSource optionDataSource = DataSource.get(foreignKeyElements[0]); if (optionDataSource == null) { throw new NullPointerException("FK DataSource not found for " + owningDataSource.getID() + ": " + dataSourceField.getName() + ": " + dataSourceField.getForeignKey()); } setOptionDataSource(optionDataSource); setTitle(optionDataSource.getTitle()); setValueField(foreignKeyElements[1]); if (optionOperationId != null) { setOptionOperationId(optionOperationId); } } }
Now, my use case is this - I want to search the grid for records that have a "name" attribute in the optiondatasource that corresponds to a search string entered by the user in a popup window..
If I do grid.getRecords() and check the contractorId, they are of course just the foreign key ID values to a record in the contractor datasource. So how do I traverse over to the contractor datasource to compare the name value there while iterating the rows in the list grid?
If I am confused, please let me know - again, hoping for help and tips.
Comment