GWT: Identify which Button in a Table was clicked - button

I am struggling with something which I think should be extremely easy.
I have a Grid in GWT, which I populate its cells with some textual data; at the last column I want to place a Button (or Image) which when clicked, I would like to take some action using the specific/associated data for that row.
I want to use a single ClickHandler for all the buttons. How can I then identify which button (and subsequently which row) has been clicked? Can I associate some sort of tag/identity value to a button (or Image) widget in GWT? With this identity/tag value, then I would be able to identify which row data I am working with.
Any clues?

In the handler use method getCellForEvent(ClickEvent event) of your Grid object. It will return HTMLTable.Cell object which has both row and column index. You pass the event object that has been delivered to the handler method. It works even if you have embed widgets in the cell and you get the click event for that widget.
Actually the method is defined in base HTMLTable, so you can use it also in FlexTable.

Related

WKSwipeGestureRecognizer not working in cell of WKInterfaceTable

I'd like to get swipes on certain cells within a WKInterfaceTable.
It is possible to add a WKSwipeGestureRecognizer to a group within a cell but the action is never called.
Adding the recognizer to the table works but this way I cannot get a reference to the cell that was tapped.
Any ideas/ or solutions to this issue?

Using bindings with BrazosUI buttons

I'm used to using boolean bindings with IBM buttons to track if a button is clicked. The button in Brazos UI can be bound to any variable type but doesn't make automatic updates to booleans. How do I use bindings with Brazos UI buttons to track which was last-clicked?
The binding of a button is really only useful in tables. The acceptance of ANY variable type for the binding of a button stems from the use of determining the index of a selected row or obtaining the entire row object:
If you bind and integer to the button in a table, the binding will update with the index of the row when the button is clicked.
If you bind a variable of the same (singular) type as the table's binding, then clicking the button will update the binding with that row's data.
Both of those are handy interactions with the table control but don't work for tracking which button is clicked when used elsewhere on a coach. For that, you want to utilize the 'Button Control ID' configuration option. The most direct method is to bind the same string variable to all of the buttons you need to track. When clicked, a button will update that shared variable to match its own control ID. You can then use that unique ID in various scripting checks to take button-specific actions.
See the BP3 Help Center article for greater detail about this, including some examples: https://support.bp-3.com/hc/en-us/articles/217985767-Using-Button-Binding-with-Brazos-UI

How can I add rows of data with dynamic images in Flex?

I want to add specific images to a datagrid row, depending on the data displayed on that row. These images need to be functional buttons with click handlers and everything.
For example, if a row displays status of a certain element, like "Editable" then the image displayed in the cell next to it needs to be a green flag, if it isn't Editable then I red flag should appear.
If you just need images and click handlers, there is an option to embed icons inside a datagrid.
Also, for a datagrid ,clicking on any row triggers the click event,the handler to which will give you datagrid.selectedIndex as the index of the row you clicked, which you can then use to get the data in that specific row and according to the data do a specific action you need.
To render icons in datagrid, you might want to check for labelFunction attribute, which allows you to specify a function , each time data in a datagrid row is filled, which yuo can use to determine the icon you would need the datagrid to render and show to the user.

Flex DataGrid prevent a filter from being applied automatically

To situate things I am working on a translation utility with a datagrid having 3 columns : translation code, reference text and target text.
The DataGrid's dataProvider property is bound to an ArrayCollection instance. The user can edit the grid and on a successful edit, the underlying collection is updated using the setItemAt() method. The collection also has a filter function to make it easier to find certain texts.
When the user clicks the 'apply filter' button the filter function is updated. This works well. The problem I have is that rows are hidden as soon as the underlying collection item change in a way that doesn't comply with the filter. The row is hidden immediately, which is not very user friendly. Rows should only hide (or be shown) when the 'apply filter' button is pressed.
I'm searching for a way to make this happen.
I assume you mean that the DataGrid's dataProvider is bound to an ArrayCollection instance?
Anyway, if you want to filter the DataGrid's dataProvider then that will remove rows from the DataGrid. You can remove the filter to add them back in. Something, conceptually like this:
collection.filterFunction = null;
collection.refresh();
If you are using the dataProvider as a source for multiple components, you can keep the filtering separate by using a different ListCollectionView for each one, but with the same source. Something like this:
component1.dataProvider = ListCollectionView(mySource);
component1.dataProvider = ListCollectionView(mySource);
Now applying a filter to one dataProvider will not affect the other.
If this doesn't help, you'll need to expand on the issue you're having and perhaps provide sample code.
After asking and looking around, I determine that there is no real way to do this. I did solve my problem however, by doing the filtering myself and only keeping a list of 'primary keys'. I then use that list to filter the collection.
The result is that rows can't suddenly disappear when records are changed, which is what I wanted.

how to loop over a datagrids rows in flex

I have a DataGrid which contains a DataGridColumn with a textinput and DataGridColumn with a Button.
The DataGrid is bound to some XML which displays values in the text box.
When the button for a row is clicked I need to get the value out of the text box and save it into the relevant XML node.
My solution was just to pass the id of the row to the button click event then loop over the rows until I find the id then just grab the text box value. Simple.
However the only advice I can find on looping over the rows is via the underlying dataProvider, which is nonsense as the two aren't the same thing.
Is this even possible? or is there a better way?
NOTE I would prefer not re-writing the markup, unless I have to.
Thanks
You are probably using an itemRenderer for your DataGridColumn to show the textBox (aka, TextInput component). I suggest that you dispatch a custom event out of the TextInput itemRenderer when you have a TextInput.dataChange event (or some other TextInput.Event that suits when you are ready to save the value).
http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html
Please remember that you need to bubble this event handling outside of the itemRenderer (e.g., the DataGrid) -- itemRenderers don't handle events well.
Also, one reason that a button to save your TextInput value is not a good idea, is because they are both itemRenderers, and it is hard to communicate between itemRenderers -- it is hard because Adobe deems it unclean code.
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
Also, this is another solution that changes the dataProvider for a ComboBox (in your case, it's a TextInput instead of ComboBox):
http://www.switchonthecode.com/tutorials/simple-datagrid-item-editor-in-flex
listData.rowIndex from the itemRenderer returns the current row index. You can read it from the click handler as:
private function clickHandler(event:MouseEvent):void
{
var listData:BaseListData = IDropInListItemRenderer(event.target).listData;
var clickedRowIndex:Number = listData.rowIndex;
}

Resources