|
|||||||
![]() |
|
|
Thread Tools | Search this Thread |
|
#1
|
|||
|
|||
|
Currently using smarclient 3.0 on RHEL 5.x and firefox 10. I have a listgrid with the filter editor visible. 3 columns have select items with datasources. They are multiple selects. One of these columns I'd like it to depend on another one, with the 3rd one independent. However, I'm stuck trying to get the selections from the first select item and creating the criteria for the 2nd one. Is it possible to achieve this for multiple select items? Is there an example I can look at or any advice I can have?
Code:
// Get the master field and set its datasource
ListGridField masterField = theListGrid.getField(masterFieldName);
masterField.setOptionDataSource(DataSource.get(masterDataSourceName));
masterField.setAutoFetchDisplayMap(true);
// Get the dependent field and set its datasource
final ListGridField dependentField = theListGrid.getField(dependentFieldName);
dependentField.setOptionDataSource(DataSource.get(dependentDataSourceName));
dependentField.setAutoFetchDisplayMap(true);
SelectItem selectItem = new SelectItem();
selectItem.setMultiple(true);
selectItem.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event)
{
String selectedItem = (String) event.getValue();
/*dependentField.setOptionCriteria(optionCriteria);*/
}
});
selectItem.setAllowEmptyValue(true);
SelectItem dependentSelectItem = new SelectItem();
dependentSelectItem.setMultiple(true);
masterField.setEditorType(selectItem);
dependentField.setEditorType(dependentSelectItem);
}
|
|
#2
|
|||
|
|||
|
The DataBound Dependent Selects example (specifically, the variant for grid editing) shows the right approach - the event in the Changed handle provides the form, from which you can retrieve the FormItem for the related field and call setOptionCriteria().
|
|
#3
|
|||
|
|||
|
I am unable to get the dependent field select item to filter down the items displayed. Here is my code. In the method that responds to the changedEvent it successfully clears the selected item for the dependent field. When I call setOptionCriteria then I go back and click on the dependent item all the items are all there with no change no matter what i click on the master field. I tried adding the setPickListFilterCriteriaFunction and hardcoded some values there but nothing worked. What am I missing here?
Code:
// Get the master field and set its datasource
ListGridField masterField = theListGrid.getField(masterFieldName);
// Get the dependent field and set its datasource
ListGridField dependentField = theListGrid.getField(dependentFieldName);
/* create the dependent select item and set its datasource */
SelectItem dependentSelectItem = new SelectItem();
dependentSelectItem.setMultiple(true);
dependentSelectItem.setOptionDataSource(DataSource.get(dependentDataSourceName));
/* create the master select item and set its datasource */
SelectItem masterSelectItem = new SelectItem();
masterSelectItem.setMultiple(true);
masterSelectItem.setOptionDataSource(DataSource.get(masterDataSourceName));
masterSelectItem.setAllowEmptyValue(true);
masterSelectItem.addChangedHandler(new ChangedHandler()
{
public void onChanged(ChangedEvent event)
{
FormItem masterSelectedItem = event.getForm().getItem(masterFieldName);
FormItem dependentItem = event.getForm().getItem(dependentFieldName);
dependentItem.clearValue();
Criteria criteriaToUse = masterSelectedItem.getCriterion();
if(criteriaToUse != null)
{
dependentItem.setOptionCriteria(criteriaToUse);
}
else
{
dependentItem.setOptionCriteria(new Criteria("PT.NAME", "Fu Bar"));
}
}
});
dependentSelectItem.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction() {
@Override
public Criteria getCriteria(FormItemFunctionContext itemContext)
{
FormItem formItem = itemContext.getFormItem();
Criteria criteriaToUse = formItem.getOptionCriteria();
return criteriaToUse;
}
});
/* set the fields to use the select items we created */
masterField.setFilterEditorType(masterSelectItem);
dependentField.setFilterEditorType(dependentSelectItem);
|
|
#4
|
|||
|
|||
|
Sorry, when you mentioned setOptionCriteria(), we erroneously referred to that same method, but it's not part of the correct approach. Instead, if you look at the sample we referred to (right here), it uses a different, correct approach instead.
|
|
#5
|
|||
|
|||
|
That is the example I have been following. I have tried several approaches to get the dependent select item to filter properly. Here are the approaches I've tried:
Code:
dependentSelectItem.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction() {
@Override
public Criteria getCriteria(FormItemFunctionContext itemContext)
{
FormItem formItem = itemContext.getFormItem();
/* TODO doesn't work */
Criteria criteriaToUse = formItem.getOptionCriteria();
/* TODO doesn't work */
criteriaToUse = theListGrid.getField(masterFieldName).getOptionCriteria();
/* TODO doesn't work */
criteriaToUse = masterSelectItem.getPickListCriteria();
/* TODO doesn't work */
criteriaToUse = masterSelectItem.getOptionCriteria();
/* TODO doesn't work */
//criteriaToUse = masterSelectItem.getCriterion();
/* TODO doesn't work */
criteriaToUse = theListGrid.getFilterEditorCriteria();
return criteriaToUse;
}
});
Code:
<fields>
<field name="NAME" type="text" length="40" primaryKey="true"/>
</fields>
<operationBindings>
<OperationBinding>
<operationType>fetch</operationType>
<selectClause> distinct PAT.NAME
</selectClause>
<tableClause> PAT
inner join PTYPE on PTYPE.PTYPE_id = PAT.PTYPE_id
</tableClause>
<whereClause>($defaultWhereClause)</whereClause>
<orderClause>PAT.NAME ASC</orderClause>
</OperationBinding>
</operationBindings>
</DataSource>
Code:
distinct PAT.NAME
FROM PAT
inner join PTYPE on PTYPE.PTYPE_id = PAT.PTYPE_id
WHERE (('1'='1' AND '1'='1')) ORDER BY PAT.NAME ASC
Code:
distinct PAT.NAME
FROM PAT
inner join PTYPE on PTYPE.PTYPE_id = PAT.PTYPE_id
WHERE (('1'='1' AND PTYPE.NAME IN ('FU BAR'))) ORDER BY PAT.NAME ASC
|
|
#6
|
|||
|
|||
|
Well, this is odd, it seems like instead of following the approach from the sample you just tried calling all the methods you could find that return Criteria :) Predictably this makes for nonsense code.
Like the sample, you want to form Criteria based on the value of the related field. The sample shows getting the related value via getEditedCell(), and equivalent approach in your case is itemContext.getFormItem().getForm().getValue(other FieldName). |
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple select item on listgrid problem | azuniga | Technical Q&A | 11 | 22nd Jun 2012 02:23 |
| setOptionalDataSource on ComboboxItem fires queries rapidly. Is this a bug? | curiousgally | Smart GWT Technical Q&A | 3 | 30th Nov 2011 09:46 |
| Blanking out dependent select values | RHelgeson | Technical Q&A | 4 | 17th Apr 2009 17:05 |
| Assign Value of a ListGrid Cell to a TextItem during onRecordClick Event of the Grid | ADA | Smart GWT Technical Q&A | 4 | 4th Mar 2009 20:21 |
| Filtering dependent select lists | mcaspar3 | Technical Q&A | 5 | 21st Sep 2007 09:42 |