I have got a Vaadin Combobox (Vaadin 8) to which I add two items. I would like that ComboBox to propose all views to which the user is supposed to navigate by a Vaadin NativeButton as described in the code snippet. In spite of the fact that "ContactView" is proposed below the ComboBox as soon as I type a "C", I cannot select "ResourceView" - and yet I have added it to theComboBox. What did I get wrong so that there is no correct dropdown?
navigatorCombobox = new ComboBox<String>("Navigate to...");
navigatorCombobox.setItems(Arrays.asList("ContactView", "ResourceView"));
navigatorButton = new NativeButton("go");
navigatorButton.addClickListener(
event -> {
if(StringUtils.isNotEmpty(navigatorCombobox.getValue()) && navigatorCombobox.getValue().equals("ContactView")) {
getUI().getNavigator().navigateTo(MynavigatorUI.CONTACTVIEW);
} else if (StringUtils.isNotEmpty(navigatorCombobox.getValue()) && navigatorCombobox.getValue().equals("ResourceView")) {
getUI().getNavigator().navigateTo(MynavigatorUI.RESOURCEVIEW);
}
});
This is intended behavior. Once you type "C" in the field, ComboBox will limit selectable options to those starting with "C".
Related
I am using Kendo combobox which has almost 4 values. I want the value to be autoselected if only one value is filtered in combobox.
For example my combobox is having below values:
India
Australia
US
UK
If I type "In" in my combobox, onchange India should be selected automatically. Can someone please guide me how to implement this
I got the solution for this:
var widget = $(".myComboBox").data("kendoComboBox");
if (widget.selectedIndex === -1 && widget.value()) {
if (widget.dataSource.view().length > 0) {
widget.select(0)
} else {
widget.value("");
}
}
Use "onFiltering" or "onDataBound" event. Check for length and use
$("#id").data("kendoDropDownList").select(0) syntax.
In my application I hava combobox which is holding some values from databse ( some real time updated list ). This ComboBox list is updated every 1 minute.
List dosen't have null values. When I'm setting this list to ComboBox..
ComboBox box = new ComboBox(items);
.. there is one extra "empty" row, which is perfectly fine because non value is selected.
Right after I'm selecting some value my "empty" value disappears from the list.
My main question is How to keep this value on the list?
Why this is a problem..
Scenerio values is selected in database, first application start
List is loaded ( wiht selected empty value ).
Value is selected.
During first background refresh, empty values disappears, and combobox value is selected to n+1, next value is selected.
If I want to select empty values I have to all clearSelection from selection model / by some extra control.
While it is an old question, I spent quite bit of time trying to solve the same issue in my application and thought i might as well add my solution here.
One possible workaround is to create an extra list that contains null and the items you wish to be selectable.
ObservableList<String> selectableActivities = FXCollections.observableArrayList("a", "b", "c");
ObservableList<String> selectableActivitiesWithNull = FXCollections.observableArrayList();;
selectableActivitiesWithNull.add(null);
selectableActivitiesWithNull.addAll(selectableActivities);
In order to support updates of the original list you would need a ListChangeListener that updates the extra list according to changes in the original list.
selectableActivities.addListener((ListChangeListener<String>)(change -> {
while (change.next()) {
if (change.wasPermutated()) {
selectableActivitiesWithNull.sort((a, b) -> {
return Integer.compare(selectableActivities.indexOf(a), selectableActivities.indexOf(b));
});
} else if (change.wasRemoved()) {
selectableActivitiesWithNull.remove(change.getFrom()+1, change.getTo()+2);
} else if (change.wasAdded()) {
selectableActivitiesWithNull.addAll(change.getFrom()+1, selectableActivities.subList(change.getFrom(), change.getTo()));
} else if (change.wasUpdated()) {
for (int i = change.getFrom(); i < change.getTo(); ++i) {
selectableActivitiesWithNull.set(i+1, selectableActivities.get(i));
}
}
}
}));
And finally you use the extra list for the ComboBox items.
ComboBox<String> combobox = new ComboBox<String>();
combobox.setItems(selectableActivitiesWithNull);
Now you can modify the original list as usual and the ComboBox will update accordingly while also having an empty selection as the first item. And most importantly your original list will not be polluted by placeholder objects that could cause issues in other parts of the application.
This will also work with other objects, assuming that you add an apropriate StringConverter to the ComboBox. Note that the converter must also be able to handle null values if using the above approach.
StringConverter<Object> activityConverter = new StringConverter<Object>() {
#Override
public String toString(Object object) {
return object != null ? object.toString() : "";
}
#Override
public ActivityDataRow fromString(String string) {
return null;
}
};
combobox.setConverter(activityConverter);
While this approach is not exactly what you desired, I believe this is a close you can get without implementing a custom combobox.
I'm working with an ExtJS 4 propertygrid that can list three different kinds of items that display when clicked on in another grid. One kind of item has to have a particular field hidden, so that it is't shown but any updates caused by editing other fields aren't affected by potentially missing information.
Attempts of using hidden/isHidden/visible/isVisible, with quoted and unquoted true/false values, haven't worked, and show the ShapeLength field in the propertyGrid.
Is there a "hidden: true" setting within the sourceConfig that I can apply somehow?
Example code:
var lengthDisplayName = '';
if(record.data.Type_ID == 'Circle(s)'){
lengthDisplayName = 'Radius (mm)';
}
if(record.data.Type_ID == 'Triangle(s)'){
lengthDisplayName = 'Side Length (mm)';
}
detailsGrid.sourceConfig['ShapeLength'] = {displayName: lengthDisplayName, type: 'number'};
if(record.data.Item_No == '-1'){
detailsGrid.sourceConfig['ShapeLength'] = {
displayName: lengthDisplayName,
type: 'number'
//, hidden/isVisible/visible value set here
}
};
No there is no hidden property for sourceConfig. But one possibility is to remove the property from the sourceConfig and reinsert it if it should be visible again.
delete detailsGrid.sourceConfig['ShapeLength'];
Was directed to an answer by a colleague - I can getRowClass within the propertyGrid and apply a hidden style on source data for an identifying property and the row name to hide, or else return out:
detailsGrid.getView().getRowClass = function(row) {
if(detailsGrid.source['Item_No'] == '-1' && row.data.name == 'ShapeLength')
return 'x-hidden';
return;
};
I am new to NatTable. I have gone thorough the NatTable examples and its source code but am not getting a solution to one of my problems.
In the NatTable I have a column that should provide a checkbox for selection depending on the value of another column.
I have used Checkboxpainter, checkboxcelleditor, the defaultbooleanconverter and IEditableRule. This renders a checkbox irrespective of whether the cell is editable or not though it allows me to mark the checkbox only if it is enabled.
However as per our requirement user should not see the checkbox if the row is not selectable. or in worst case a disabledcheckbox should be rendered for rows that are not selectable.
Can someone please help me out?
Thanks and regards,
Pradyumna
Got a solution for this.
I had to write a custom checkboxpainter (inheriting from the one that is available OOTB) and override its getImage method to return null for appropriate cells
There is a better solution which I have just applied to a similar case in my work.
I did it by adding the following configuration to the table:
// make checkbox cells editable
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE, DisplayMode.EDIT, CONFIG_LABEL_CHECKBOX);
// register the checkbox editor for DisplayMode.EDIT
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new CheckBoxCellEditor(), DisplayMode.EDIT, CONFIG_LABEL_CHECKBOX);
// register the checkbox painter for DisplayMode.NORMAL
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CheckBoxPainter(), DisplayMode.NORMAL, CONFIG_LABEL_CHECKBOX);
// register the painter for empty cells in DisplayMode.NORMAL
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(), DisplayMode.NORMAL, CONFIG_LABEL_EMPTY);
Basically, this introduces the configuration labels CONFIG_LABEL_CHECKBOX for an editable checkbox, and CONFIG_LABEL_EMPTY for an empty cell.
Now all you have to do is to attach an IConfigLabelAccumulator to your bodyDataLayer:
bodyDataLayer.setConfigLabelAccumulator(new IConfigLabelAccumulator()
{
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition)
{
if(columnPosition == CHECKBOX_COLUMN_INDEX)
{
if(someCodeToCheckIfRowIsEditable(rowPosition))
{
configLabels.add(CONFIG_LABEL_CHECKBOX);
}
else
{
configLabels.add(CONFIG_LABEL_EMPTY);
}
}
}
}
I have a QListView displaying a list of items but I don't want the items to be edited (Currently a double click on the item allows you to edit them).
This is my Code:
self.listView = QListView()
self.model = QStringListModel([ "item1" , "item2" , "item3" ])
self.listView.setModel( self.model )
self.layout = QGridLayout()
self.layout.addWidget(self.listView, 0 , 0 )
self.setLayout(self.layout)
Adding the line:
self.listView.setEditTriggers(QAbstractItemView.NoEditTriggers)
should fix things for you.
QListView inherits QAbstractItemView which has the method setEditTriggers(). Other possible values for setEditTriggers are available in the docs.
Thanks for the responses. I ended up going with a QListWidget instead as it is not editable by default.
Though I also found if you give the QListView a mouse Double clicked event and set it to do something other than edit the QListView, it overrides the edit function so that works too.
If model will be attached to multiple views and you don't want it to be editable by any of them, you can subclass QStringListModel and override flags():
from PyQt5.QtCore import Qt
class UneditableStringListModel(QStringListModel):
def flags(self, index):
return Qt.ItemIsSelectable & Qt.ItemIsEnabled
listView = QListView()
model = UneditableStringListModel([ "item1" , "item2" , "item3" ])
listView.setModel(model)
Now the user will not be able to edit model from any view.
QStringListModel is by definition editable. You should subclass and provide the appropriate flags