How to get the selected row id of a GridPanel - selecteditem

I have a GridPanel named GridPanel1 and a button to remove the selected row of the GridPanel,
I want to get the selected row id by clicking a ext button and send the id to a directMethod.
My code is:
var removeEmployee = function () {
// CompanyZ.Delete(id); // Here I need the GridPanel selected row id
console.log(mygrid);
}
Please can anyone help me?

Please use:
grid.getSelectionModel().getSelection()[0].getId()

Related

How determine if a Vaadin table row clicked in has been selected or deselected?

Following a user clicking in a row in a Vaadin 7 table, how can I tell
if the row has been selected or deselected - clicking in a selected row deselects the row - (since there is also a column of
checkboxes which needs to kept in synch)?
When I tried table.getValue() in an ItemClickListener, this returned null if the
row is selected and the item id if the row is deselected - i.e. the opposite of
what I would have expected?
table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
#Override
public void itemClick(ItemClickEvent event) {
// how tell if row has been selected or deselected?
Object idx = table.getValue();
}
});
Thank you,
Steve
In the Table api you can use the getValue() method, which results the selected rows.
Depending if in multiselct mode or not, you can then deduce what happens.
Use Vaadin Grid instead of table. It has the selectionListener property which will help you achieve what you need.
Grid API
(since there is also a column of checkboxes which needs to kept in
synch)?
Use Grid ans set grid.setSelectionMode(SelectionMode.MULTI); you will have one extra column with checkboxes by default.
Now, If you don't want to use Grid.
For Table you should use vaadinTable.addValueChangeListener(...) instead of ItemClickListener.
For Example :
table.addValueChangeListener(new ValueChangeListener() {
#Override
public void valueChange(ValueChangeEvent event) {
//Set checkbox object as an itemId
CheckBox itemId = (CheckBox)event.getProperty().getValue();
//Manage Collection to add selected items
if(table.isSelected(itemId)) {
table.select(itemId);
itemId.setValue(true);//Add this item to collection
} else {
table.unselect(itemId); //Remove this item to collection
itemId.setValue(false);
}
}
});
One another option is,
table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
#Override
public void itemClick(ItemClickEvent event) {
//Manage collection and manually fetch property of table
Object value = event.getItem().getItemProperty("property").getValue();
}
});

Unhighlight first highlighted item from AutoComplete

Here I am using p:autoComplete tag in PrimeFaces 5.1, but I can't remove first highlighted/selected item from the suggestions list. How I can remove this ?
Since your "problem" comes from this particular line,
firstItem.addClass('ui-state-highlight');
What happens here is when the suggestions are ready to show up the script highlights the first item of the list, so in your case you would just "unhighlight" that item.
I have created a small function that would do that on every AutoComplete you have, you can call it in your document.ready or where ever you see suitable:
function removeHighlightedFirstItem() {
var oldAutoCompleteShowSuggestions = PrimeFaces.widget.AutoComplete.prototype.showSuggestions;
PrimeFaces.widget.AutoComplete.prototype.showSuggestions = function(query) {
//calling original ShowSuggestions
oldAutoCompleteShowSuggestions.apply(this, [query]);
//after ShowSuggestions
//remove first item highlight
var firstItem = this.items.eq(0);
firstItem.removeClass('ui-state-highlight');
}
}
The result would look like this:
Note: The feature you are requesting is available for 5.1.5, 5.0.14 and 5.2 by adding the autoHighlight = "false" attribute to the component.

ext.net radiogroup get selected items value

I have an Ext.Net Radiogroup and I have to get the selected value and then send that as a parameter to a controller action. Here is the Directevents I am attempting to use, but it doesnt' seem to work (I get null each time). Does anyone know how to get the value of the selected item?
.DirectEvents(de =>
{
de.Change.Url = Url.Action("GetItems");
de.Change.ExtraParams.Add(new Ext.Net.Parameter
{
Name = "Id",
Value = "App.myRadio.getValue() == null ? '0' : App.myRadio.getValue()",
Mode = ParameterMode.Raw
});
}),
To get an array of all the selected checkboxes/radio buttons on a radio group, you can do:
App.myRadio.getChecked();
This returns a list of all checkboxes and radio buttons that are selected on the radio group. If you only have radio buttons inside the radio group, it should return an array with just one item.
You can then get the value of the radio button like this:
App.myRadio.getChecked().length != 1 ? '0' : App.myRadio.getChecked()[0].getValue();
But this will always return a true-ish value (true, 'true', '1' or 'on') for a radio button. If you want the value on the label for that radio button, instead use the following:
App.myRadio.getChecked()[0].getFieldLabel()
Hope this helps!

Vaadin table.select(itemId) is not working

I have a table bind to a SQLContainer and a insert button (that insert a row in the table)
When the button is clicked it execute the below code of the listener:
Object itemId = table.addItem();
container.getContainerProperty(itemId, "cedula").setValue(cedulaS);
try {
container.commit();
table.select(itemId);
catch (UnsupportedOperationException e) { //bla }
The row is properly inserted BUT I want that automatically the row be selected but the select method is not working any idea?
EDIT:
The select(ItemId) is working and its select the row BUT for some reason the commit line make that the select(ItemId) didnt works. I think is because itemId is a temporary row, so when the commit is execute it disappear o lose its values.
This thread has the answer, thanks to #Teppo Kurki
https://vaadin.com/forum#!/thread/4268146
The problem is that itemId is a temporal row id so when the commit is executed iy changed the row id, so it must be implemented the below listener:
container.addRowIdChangeListener(new QueryDelegate.RowIdChangeListener() {
void rowIdChange(QueryDelegate.RowIdChangeEvent event) {
table.select(event.getNewRowId());
}
});
Ant we now can delete the table.select(itemId); in the initial post

could not be able to work with list control in flex 4.5

I want to be selected that new Item in list when I give new value to dataProvider but it selects the item that was firstly selected, and how to make that selected permanently on App start up.
You if want to select the list item after added to dataProvider. Probably you follow this
list.selectedIndex = list.dataProvider.length -1;
Sometimes if you added at desired position like
list.dataProvider.setItemAt(obj,2);
list.selectedIndex = 2
If you want to selected item permanently on App start up.(Make sure that your array collections bind-able to list)
public function onCreationComplete(event:FlexEvent):void
{
callLater(function():void
{
list.selectedIndex = list.dataProvider.length -1;
list.ensureIndexIsVisible(list.selectedIndex); // Viewport
});
}

Resources