SilverLight 4 DataGrid & MVVM: Using SelectionChanged trigger to check checkbox, but NotifyPropertyChanged causes crash - mvvm

I have a DataGridCheckBoxColumn in my DataGrid which is to indicate the rows the user has selected. I want the checkboxes to be checked/unchecked with a single click. Making the column editable (i.e. IsReadOnly="False") means the user has to click twice (first click just selects the row, 2nd click changes the checkbox), so I decided to set/clear the property the column is bound to in the view model code in response to the SelectionChanged trigger firing.
Setting/clearing the property works fine, however as soon as I call NotifyPropertyChanged("name of collection the grid is bound to") to get the view to show the change, this causes the SelectionChanged trigger to fire again. This loops about 10 times until an exception is thrown.
If I remove the call to NotifyPropertyChanged, the SelectionChanged trigger fires once, but of course I don't see any change in the UI. The collection is a PagedCollectionView if this makes any difference.
How can I get this to work? Note - I am using MVVM pattern, so everything is done with bindings to View Model (no code behind).
Thanks

Sounds like you have a infinite loop by design.
but try using the selectionchanging instead of selectionchanged,
or put a isloading flag in your viewmodel and dont call the inotify if the isloading is true

I found a very simple solution that doesn't involve triggers or code behind. See: Silverlight single-click checkbox DataGrid columns
It seems to work by using a column template, but only providing the CellEditingTemplate and no CellTemplate.

Related

Tabulator column.setWidth() not saving to history

I have a headerMenu dropdown to "show" and "hide" columns, and persistence is set to true. When I manually resize the columns the new width is persistent, but it is not when using the dropdown (the column does resize, however, it just doesn't stay that way on the next reload). I noticed that the columnResized callback is also not triggered by my code.
var headerMenu = [
{
label:"Hide Column",
action:function(e, column){
column.setWidth(40);
}
},
Am I missing something here? How do I get this to work and be persistent?
This is the correct behaviour, and fairly standard across a range of table functions and callbacks
Both the callback and the persistence module only track user interaction with the table. This allows maximum flexibility for the developer to call additional functions on the table with out interfering with the direct user experience.
In your case you appear to be trying to hide a column by changing its width? there is a hide function you can call on a column to hide it, if that is what y0u are attempting.
column.hide()

How to configure agGrid grouping so it works like an accordion

is it possible to configure agGrid grouping so that it behaves like an accordion i.e. only one group can be expanded and when opening new group previously opened is closed?
Not sure if this answers your question, but I am sure this might be the only direction you'll have.
There is a method provided on gridApi - onGroupExpandedOrCollapsed
So I think (again, need to check) that this function would be called as its name suggests, and you can collapse the other rows (whichever is opened) and achieve your functionality.
Be cautious while using this as there is comment given by ag-grid
we don't really want the user calling this if one one rowNode was
expanded, instead they should be calling rowNode.setExpanded(boolean)
- this way we do a 'keepRenderedRows=false' so that the whole grid gets refreshed again - otherwise the row with the rowNodes that were
changed won't get updated, and thus the expand icon in the group cell
won't get 'opened' or 'closed'.

GWT how to change textbox without running change handler

I am using GWT. I have a textbox and a drop down list box that have change handlers on them. I also sometimes change the text or selected value from the source code but I don't want the change handler to run when I do this, I only want it to run when the user changes it.
How can I implement this?
For the TextBox, use setValue(T value, boolean fireEvents) using false as second argument, to avoid firing any ValueChangeEvent.
For the ListBox, when you call setSelectedIndex(int index) or setItemSelected(int index, boolean selected) the ChangeEvent is never fired, so you are free to use them programmatically and rely on the ChangeHandler on user action.

Change the order of event handling in GWT

I have a Suggest box which has 2 hadlers: SelectionHandler for selecting items in SuggestionList and keyDownHandler on TextBox of SuggestBox. I want to prevent default action on event(for example on Enter pressed) when the suggestion list is currently showing. The problem is that SelectionEvent is always fires before KeyDownEvent and suggestion list is closed after SuggestionEvent fired, so in KeyDownEventHandler suggestion list is already closed. And I can't use prevent default action on Enter with checking the suggestion list is showing like this:
if ((nativeCode == KeyCodes.KEY_TAB || nativeCode == KeyCodes.KEY_ENTER) && display.isSuggestionListShowing()) {
event.preventDefault();
}
where display.isSuggestionListShowing() is the method which calls isShowing on SuggestBox .
So how can i change the order of event handling(Selection before KeyDown to the keyDown before Selection) in this case?
I'm assuming you mean SuggestBox instead of SuggestionList, as there is no class by that name in the gwt-user jar.
The SuggestBox uses the keydown event to provide the SelectEvent - if it can't see the keys change (from the browser, which actually picks up the user's action), it can't provide the logical selection event.
This means that reordering events doesn't really make sense - you can't have the effect before the cause. In many cases, the browser emits events in a certain order, and there is no way to change this, so you have to think differently about the problem.
(Also worth pointing out that preventDefault() only prevents the browser from doing its default behavior - other handlers will still fire as normal.)
One option would be to preview all events before they get to the SuggestBox, and cancel the event in certain cases - look into com.google.gwt.user.client.Event.addNativePreviewHandler(NativePreviewHandler) for how this can be done.
I'm not seeing any other option right away - all of the actual logic for handling the keydown is wrapped up in the inner class in the private method of com.google.gwt.user.client.ui.SuggestBox.addEventsToTextBox(), leaving no options for overriding it.

wicket: Dropdownchoice

i have two dropdowns using same model and sets the value into it. Dropdown1 will visible on screen always and Dropdown2, will be visible for only one particular option choosen in Dropdown1. and i am making an query to the DB based on the selections in dropdowns.
But when i have both the dropdown first and then hide the second one, The value already set but the Dropdown2 is still avalible in my model, and making my query to fetch improper data.
So can any one suggest me an idea, how to set the value to null for the attribute which is actually set but dropdown2, if dropdown2 is inVisible.
(i tried to set the ModelObject to null, when making the dropdown2 invisible (using AjaxFormComponentupdateBehavior), but when i make the dropdown2, visible again, it returns null,even if i make any selection in it)
Are you using a LoadableDetachableModel ? try to explicitly detach model from that dropdown on setHide event. I did not try it though.