I am using a WinJS.Binding.List to bind data to a ListView. I would like to use the createSorted method to create a sorted projection on the list. In addition, the data inside the list is live so it will be changing. Obviously the sorted projection will not automatically watch the properties to see if they are changing. I can't find a mechanism that will allow me to invoked a 're-sort'. Does something like that exist?
The list should automatically re-sort itself if you use the WinJS.Binding.mixin or WinJS.Binding.as on the elements in your list.
This will make them observable by the list and it should not only update any bound properties you reference in your itemTemplate but also re-sort the list when using projections.
http://msdn.microsoft.com/en-us/library/windows/apps/br211859.aspx
I believe you will need to call notifyMutated on the list at that item.
http://msdn.microsoft.com/en-us/library/windows/apps/hh700771.aspx
Related
Observe the following classes and their containment:
Section has an ItemList which has many Items
But lets say an Item is rendered a different color based on some complicated algorithm that is based off the Section.name it is contained in.
What's the proper/best way to go about abstracting this functionality? Is there a common design pattern that occurs in situations like these? Or is the inherent design flawed?
You should separate your data structures/models from your logic and processing of them. That said, I would make your Item have a Section reference on it referencing it's Section, when you add an Item to the ItemList, ensure the add method looks at the ItemLists Section (parent) and sets the reference on the Item. Same goes for the setter on the ItemList in the Section, it would have to iterate each Item and set the Section.
Alternatively, you could make the Section set on the getter of the ItemList as lazy semantics, that would be entirely up to you depending on the use of your Section the performance statistics would be different between these two approaches.
Further, I would write some form of renderer that took an Item and knew how to render it which would look at the Section on the Item and the Name on that Section.
You may want to render an entire section, but I would write that renderer separate and it would use the ItemRenderer to render each Item.
As an aside, you may want to use a form of IObservableCollection and have the Item implement INotifyPropertyChanged as well so that you could then maintain synchrony both between the rendered version and the item, and synchronize the Item with the Section it exists in by an event registration that updates the Section property appropriately.
What does the rendering? If it's something in Section, or outside of all of these, but accessing the Items from the Section, then there's nothing more needed.
If it's in Item, then you just need to make sure Item knows what Section it belongs to, or can obtain it (e.g. by having an ID it can look up on - useful with languages that make dealing with circular references tricky, but not needless hassle otherwise).
Since the first case causes no difficulty, it's clearly to be preferred over the second, so the closest to a design-pattern is that if you find yourself doing this sort of work in the contained item, to try and move it up to the container, or outside of them all. Beyond that, there isn't much of a problem to need solving.
I would build an ItemRenderer class that knows the algorithm, and pass in the references to each Item you would like to render and the Section it was contained in.
It may also make sense to let each Item know the section it belongs to, but I would still let the ItemRenderer handle the rendering.
When i define a control in DataTemplate, how to get reference of this control ?
If the control in ControlTemplate of Style , how to get ?
You should instead tell us why you would need to reference a control inside a template.
Consider that the control will be rendered multiple times, so getting a single reference does simply not make any sense.
The most common approach to this is to 'name' the element that you wish to locate via x:Name="MyElementName", you can then use the FindName method to locate the names element. If your DataTemplate is being used in an ItemsControl to render multiple copies of yoru XAML markup, then clearly there will be a number of elements that share this same name. For this reason, there is a concept known as XAML namescope, you should read up on this to understand the scope of the name you provide.
If you require a more generic method for searching for elements in the visual tree, try Linq-to-VisualTree, you can use it to query you UI, for example:
var itemsFluent = this.Descendants<TextBox>()
.Where(i => i.Ancestors().FirstOrDefault() is Grid);
The above query will find all TextBoxs that have a Grid as a direct parent.
Finally, if you can avoid doing any of this, by using databinding, or event bubbling then do so! it is much easier.
I have a simple tree grid and i need to programmatically expand a row to show its children. In essence i need to fake the click event that triggers the opening of the tree.
see and example here http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_treegrid_model_lazy.html
I haven't personally used the TreeGrid, but from the API docs, it looks like you want to use the expandoFetch(rowIndex,open) function with the open parameter as true:
myTreeGrid.expandoFetch(0,true);
I am trying to delete the selected record from the drop-down grid.
In trying to do this, I've so far learned that DSOperationType.FETCH is called when the fetchData() method is called on ValuesManager class. So now I want to know what line should be executed for calling DSOperationType.REMOVE.
Or is there a better way to accomplish this task?
DSOperationType.REMOVE will be called only when removing data/row from list grid or tree grid. It can be triggered functionally by calling ListGrid.removeData(someData) or ListGrid.removeSelectedData();
But for ComboBox/SelectBox (DropDown) type item there is no functionality to remove data from list as it can only be selected from a list of data (while loading data for list FETCH operation will be called).
You can implement the functionlity indirectly by using Combobox/SelectItem with listgrid - (ex:http://www.smartclient.com/smartgwt/showcase/#dropdown_grid_combobox_category). In listgrid you can have remove data functionality. Also check other types of functionality that can be implemented with combobx http://www.smartclient.com/smartgwt/showcase/#multi_select_combobox_category
I have a question with Value Converters, I have an array w/c filters inactive item, when I am editing an item and change the status property to 'INACTV', the table does not change. but when adding/removing items in the array, it refreshes, my workaround is creating a binded _signal property to force the filtering, is there a way not to do this?
< tr repeat.for="item of ARRAY | filtercustom:'STATUS_CD':'INACTV':_signal" >
I'm not sure I understood how the filter is supposed to work. But if it should hide inactive items, maybe you could do something like
<tr repeat.for="item of ARRAY" if.bind="!item.STATUS_CD='INACTV'">
I don't know if it is possible to put a value converter inside a "repeat.for". Looks weird.
I hope this helps to push you in the right direction.
No, there is no direct, clean way to do this at the moment. Repeat.for uses a CollectionObserver for array observation which only responds to pop/push/reverse/shift/sort/splice/unshift.
Only when one of these methods is called on the array, the observer fires and the array is fed to your ValueConverter again.
Your signal solution is about as clean as it gets. It's more efficient than the alternative of refreshing the whole array from manually instantiated property observers on your STATUS_CD property on every item in the array.
Which is what I do in some similar situations, because I don't like using signals. But that's just a matter of preference.