Vaadin Flow Grid. How to select one row programmatically? - vaadin10

i try to implement navigation with key arrow in the grid.
to do this i need to able select one row per row index programmatically.
How can i do this?
thx.

Vaadin Flow Grid has method Grid.select(item), which selects item programmatically. So you need to resolve the item. The best way to get it, is to use Grid.getDataCommunicator() which has the following method, fetchFromProvider:
https://demo.vaadin.com/javadoc/com.vaadin/vaadin-core/10.0.2/com/vaadin/flow/data/provider/DataCommunicator.html#fetchFromProvider-int-int-
So fetchFromProvider(rowIndex,1) returns the item you want to select.

You can use the defined SelectionModel of your grid.
private Grid<Customer> customerGrid = new Grid<>();
customerGrid.getSelectionModel().select([enter your logic for identifying the customer of your wish]);

Use the following API (since Vaadin 17)
Person item = grid.getDataCommunicator().getItem(42);
grid.select(item);
or
Person item = grid.getGenericDataView().getItem(42);
grid.select(item);

Related

How can i scroll to currently selected row in Vaadin grid?

this.grid.asSingleSelect().addValueChangeListener(event -> {
if (!Objects.isNull(event.getValue())) {
this.editor.showEditor(event.getValue());
}
});
The problem is that editor covers half of grid when it's displayed. How can i scroll to selected row before showing it?
I know that you can this.grid.scrollTo(rowId);, but i can't find a way to get id of currently selected row.
grid#scrollTo
grid.scrollTo(rowForValue, ScrollDestination.START);
In Vaadin 8 you should able to use grid#getSelectedItems
public Set<T> getSelectedItems()
method to get selected items, if your selection mode is single select, it returns set of one item.

How to create a Hierarchical menu in iOS?

In my application, I have a menu that is defined as follows. Each item on the menu is a node that has the following data attributes:
MenuText : (the text that would appear for that item)
isView : Whether this item is a leaf level item or not
subMenus : if isView is false, then there are multiple menu items under this attribute.
Thus, it is a tree structure that can go till any depth. The items in the menu can change periodically and hence the implementation has to be kept flexible. This data is stored in a plist file and read into an NSArray in the code (already implemented).
I now need to create a slide out menu on the left that will be populated by this data hierarchy. I have created the menu pane and added swipe gestures to it, all of which work fine. The menu has to be a collapsible one where clicking on one menu item expands the subViews below it. If the item clicked on is a view, then a new view is loaded on the rest of the screen with appropriate data.
The problem I am facing is the logic to populate the menu (which is a UITableView) from the NSArray data. The following are the two approaches I came up with.
Create a UITableView with as many sections as there are items at the top level of the menu. Then iterate through the menu items recursively. For each menu item that is not a view (i.e. it has subMenus), create a new section with number of rows equal to the number of subMenus under it. When I come across a menu item that is a view and has no further subMenus, add it as a row to the subsection created for the menu one level above it.
Create a menu with one section and as many rows as the number of menu items at the top level. When a menu item is clicked, insert rows under it to represent its sub-menus. When another menu item on the same level is clicked, collapse the previously expanded menu by deleting the inserted rows. When a menu item with no sub menus is clicked, the rest of the screen is populated with data.
I have tried both the approaches and not been able to go beyond the initial steps. For the first method, I understand that I need to add a UITableView as a part of UITableViewCells, which is good, but I need to do that recursively. For the second approach, I need to know the indexPath of each item clicked which can go to many levels.
I would like some suggestions here about which approach I should take and some guidance over how to go about it. Also, if there is any better way to do this, kindly advice. Thanks.
In my opinion, using UINavigationController is the easiest way. You can push as many UITableViews as you want.
If it doesn't fit your design requirement, you can try expandable UITableViews. There are few open sources:
JKExpandTableView
SDNestedTable
iOS-Tree-Component
Thanks for the responses. I ended up doing this using the following control:
Accordion for iOS
It has served my purpose beautifully and I posted it here so that someone with the same requirement may find it.
Take a look at TLIndexPathTools. It has a "Tree" extension that can do this. Try running the Outline sample project. The main task in adapting the sample project would be to write a recursive function to convert your array of nodes into an array of TLIndexPathTreeItem objects. All of the code in the controller:willChangeNode: method is examples of lazy loading and it doesn't sound like you'd need any of that.

how to do drag and drop of record from one list view to another kendoUI

I have different list views,
I want to drag and drop of record from one list view to another.
I have seen a link in regarding this,
"http://jsfiddle.net/MZxQu/36/"
I have implemented this in list view,with this I am able to drag the list view content,but I am not able to drop it on another list view.
can u help me
Thanks..
Use this instead of grid it will be better i guess:
http://demos.kendoui.com/web/treeview/dragdrop.html

BlackBerry 6: how to scroll to a new item in KeywordFilterList?

the SearchFieldDemo works well for me, but has one problem: when you add a new country to the KeywordFilterList through the menu and that new item is on the bottom of the sorted list, then the user doesn't see anything and is unsure if the new item has been added or not.
A solution would be to make the KeywordFilterList scroll to the new item, but I can't figure out, how to do that. I've tried:
void addElementToList(Country country)
{
_countryList.addElement(country);
_keywordFilterField.updateList();
int index = _countryList.getIndex(country);
System.err.println("XXX index: " + index);
_keywordFilterField.setSelectedIndex(index);
}
But this does not have any effect: the printed index is correct and the KeywordFilterList scrolls, but not to a correct spot.
Any ideas please?
Alex
In the sample app you might have noticed the _keywordFilterField.setKeyword(""); line as the first thing they do before adding a new item to the list. This is to guarantee the new item will be visible in the list. Otherwise with some filter applied the list may not display the new item.
So in your code it looks like you don't handle this point. As a result the index you get with int index = _countryList.getIndex(country); may not be the same as it is in the visible filtered by some current keyword list. BTW, to find the index in the visible list you could use the ReadableList which can be got with _keywordFilterField.getResultList().
So the workflow could be as follows:
reset keyword by _keywordFilterField.setKeyword(""); - now there is no filtering applied so the visible list should include a new item.
add a new item to the underlying collection - _countryList.addElement(country);
call _keywordFilterField.updateList(); to refresh the ListField.
to be on the safe side find an index to scroll to by using the collection got by calling the _keywordFilterField.getResultList()
select the new item with _keywordFilterField.setSelectedIndex(index);

How can i implement an interface like BB Messenger?

How can i implement an interface like BB Messenger showing a tree with a list of complex field items that are shown only if the tree item expands.??
Use a ListField for the contents of the collapsible area (you control how each row is painted), and use some other focusable field for the header. Add both to a VerticalFieldManager. When you click on the header once, remove the ListField from the Manager. When you click on it again, add it back.
I think you are talking about tree view. for that you can try this.
Create a field to display a tree view

Resources