Titanium refreshing TableView with new data - refresh

This is what I am trying to do:
_tableView.data[0].rows[selectedPosY].children[selectedPosX].imageId = tempImageId;
_tableView.data[0].rows[selectedPosY].children[selectedPosX].image = tempImageUrl;
Titanium.API.info("imageIdSelected:" +
_tableView.data[0].rows[selectedPosY].children[selectedPosX].imageId + "imageSelected:" +
_tableView.data[0].rows[selectedPosY].children[selectedPosX].image);
The update is done on the data, but it doesn't reflect in UI table, what is missing?
I even tried doing the below as per How can I refresh my TableView in titanium? & How to resolve Titanium TableView display problem?, but it is not refreshing the UI table
_tableView.setData(_tableView.data); win.add(_tableView);

It turns out the only way to update/reload a Titanium.UI.TableView is to get a copy of the updated data (as per ones logic) and reset it in the TableView, using 'setData'. For my example, since the _tableView.data is getting updated (which could be seen through the logging statements), I could copy it using a javascript array copy function like;
var data2 =_tableView.data.slice(0);
_tableView.setData(data2);
Although, with the above knowledge, I had restructure my code, so, I am not using this exact code, but a similar logic. But, overall, this way of updating the table doesn't seem very appealing, if there is any better way of handling this, please post, it would help a lot.

Why are you doing _tableView.data[0].rows and then just _tableView.data when using setData?
Your _tableView.data should be an array of rows/sections. The Ti.UI.tableView object has the data property but the data should be structured as follows.
_tableView.data = [
{title:"Row 1"},
{title:"Row 2"}
];
What does the .rows accomplish for you when you are doing it that way, how are you using the .rows? I'm not positive but I think the _tableView.data is either no different or is invalid when trying to setData.

Related

Cant retrieve local records from store using Ember Data

I am trying to retrieve records which have already been loaded into the store by using this line in a controller:
var allProducts = this.store.all('product');
However, this is returning a strange object (see screenshot). When I call length on it, the result is "undefined." I have used the Chrome Ember inspector to confirm that records have indeed been loaded into Product before the above line of code is run. I thought since store.all returns a recordarray I could iterate over it immediately unlike a promise. Where am I going wrong please?
The strange object that is returned is a record array. This is important so that Ember can set up observers for arrays that are loaded. I believe this is what is causing your confusion. See more specifics in the docs:
It's important to note that DS.RecordArray is not a JavaScript array.
It is an object that implements Ember.Enumerable. This is important
because, for example, if you want to retrieve records by index, the []
notation will not work--you'll have to use objectAt(index) instead.
You will have to look at the documention for DS.RecordArray but you should be able to iterate over it using the forEach method. See the ember array documentation for more details.
The issue was that I was trying to iterate over the recordarray using a traditional for loop. Seems that a) recordarray cannot return length and 2) one must use a forEach loop to iterate over it, which is what I had initially did but dropped because forEach does not support break or continue.
Ahh promises! :)
You should be able to do this:
var allProducts = this.store.all('product').then(function(products) {
return products;
});

Selectable cells in UITableView with ProMotion

I’m getting crazy with Pro Motion table and I cannot find any discussion about this online.
I’m using a PM::TableScreen and I need to have selectable table rows. I manage the raw selection in an array but I don’t know how can I get the cell object to call cell.accessoryType = UITableViewCellAccessoryCheckmark if is selected or cell.accessoryType = UITableViewCellAccessoryNone if not selected.
Here is the gist of my screen: I try to intercept the cell passing a value in the arguments (row) but I cannot find a method to get the cell object.
In my original idea the place for the selection is inside my tapped_cell method byt maybe there is a better way to manage a multiselection.
My Gist
You don't want to memoize the table data. I've created a pull request with the fix:
https://github.com/robypez/rm_quiz/pull/1
Hard to summarize here, although I know Stackoverflow doesn't like us relying on links.

Find model returns undefined when trying to get the attribute of a model by first finding the model by another attribute?

I would like to do something like:
App.Model.find({unique_attribute_a: 'foo'}).objectAt(0).get('attribute_b')`
basically first finding a model by its unique attribute that is NOT its ID, then getting another attribute of that model. (objectAt(0) is used because find by attribute returns a RecordArray.)
The problem is App.Model.find({unique_attribute_a: 'foo'}).objectAt(0) is always undefined. I don't know why.
Please see the problem in the jsbin.
It looks like you want to use a filter rather than a find (or in this case a findQuery). Example here: http://jsbin.com/iwiruw/438
App.Model.find({ unique_attribute_a: 'foo' }) converts the query to an ajax query string:
/model?unique_attribute_a=foo
Ember data expects your server to return a filtered response. Ember Data then loads this response into an ImmutableArray and makes no assumption about what you were trying to find, it just knows the server returned something that matched your query and groups that result into a non-changable array (you can still modify the record, just not the array).
App.Model.filtler on the other hand just filters the local store based on your filter function. It does have one "magical" side affect where it will do App.Model.find behind the scenes if there are no models in the store although I am not sure if this is intended.
Typically I avoid filters as it can have some performance issues with large data sets and ember data. A filter must materialize every record which can be slow if you have thousands of records
Someone on irc gave me this answer. Then I modified it to make it work completely. Basically I should have used filtered.
App.Office.filter( function(e){return e.get('unique_attribute_a') == 'foo'}).objectAt(0)
Then I can get the attribute like:
App.Office.filter( function(e){return e.get('unique_attribute_a') == 'foo'}).objectAt(0).get('attribute_b')
See the code in jsbin.
Does anyone know WHY filter works but find doesn't? They both return RecordArrays.

how to copy datagrid itemsource into observable collection object in silverlight5?

I have a values in DataGrid like Name,Age,Address. I have to get datagrid values into Observable collection Object?Is it possible. .If Yes then plz anyone can tell me the solution?
(sorry for my bad english)
Why you simply dont create a ObservableCollection in the first place instead of using a List?
Anyway, you can create an ObservableCollection with the List data this way:
ObservableCollection<Customer> customers = new ObservableCollection<Customer>(YOUR_LIST);
If you really need to get the data from the DataGrid ItemsSource:
ObservableCollection<Customer> customers = new ObservableCollection<Customer>(grid.ItemsSource as List<Customer>);

How do you get child bands in ultragrid without using related tables in a dataset?

I'm using linq to pull back an object (i.e. customer) that might have a collection of other objects(customer.orders). I would be nice if I can pass this list of customers to the ultragrid and a hierarchical view of customers and thier orders displayed on databind. When I try this, I just get customers. Anyone know how to get this to work with non dataset objects?
Figured it out. IList collection works and will create bands for properties of your domain object if it is an IList<T>. Just make sure thatDisplayLayout.ViewStyle = ViewStyle.MultiBand.
I've tried the following and it didn't work:
DisplayLayout.ViewStyle = ViewStyle.MultiBand
I read from this blog that it must be List and not IList in order to work, and it did.
We work with our own custom datasource for grid, so we first create a structure of bands and then we initialize data OnDemand, handling events
InitializeDataRow
InitializeRowsCollection
CellDataRequested
We use Tags to navigate through the structure.