How do I dynamically update JTable in View Observer? - model-view-controller

I have a View class that is an Observer of a Model. The view class has an Update() method which receives an array whenever that array is updated. I have verified the array is received, after which a new table model is created and applied to the JTable using the setModel() method.
The problem is, the table view is not visibly refreshed until the controller's file processing loop ends.
My goal is to have the table view be updated in realtime (dynamically), whenever its underlying data model is updated.

Related

How does an MVC System View element know when to update?

For example in AngularJS if you bind an ng-model to an ng-repeater, and your controller calls a service that updates the model, then the repeater is updated to reflect the change.
My question is, how does the view element (in this example, the ng-repeater) know to be updated?
For example, is there a timer that fires every couple milliseconds and updates the UI (unlikely)? Does the controller or view implement some type of internal event listener for all bindings and when the model updates, it fires a re-layout of the associated view elements?
When we write an expression ({{dyanvar}}), behind the scenes Angular sets up a watcher on the scope model, which in turn updates the view whenever the model changes. This watcher is like any other watcher we set up in AngularJS:
$scope.$watch('dyanvar', function(newValue, oldValue) {
//update the view with newValue
});
The second argument passed to $watch() is known as a listener function, and It is called whenever the value of dyanvar changes.
Your answer is in this article :
https://cfdeepak.wordpress.com/2014/09/29/how-two-way-data-binding-works-in-angular-js/

Display multiple new rows in Kendo Grid

I am doing an inline add using Kendo Grid, but on the server side I am actually creating multiple records. The DataSourceRequest sends back all the newly created rows, but only one is added to the grid. The other added records may not show up in the grid at all until the grid is forced to query for the data again.
Is there a way for me to add multiple rows at once?
If not, is there a way to re-query the data and put all newly added models at the top?
In my controller function that creates the new records, I am returning the following. "models" contains all of the newly created records:
return this.Json(models.ToDataSourceResult(request, this.ModelState), JsonRequestBehavior.AllowGet);
I also have a similar issue when updating a row since the server may actually update multiple rows. Since "models" contains multiple models, the first one in the list may or may not be the actual model selected to be updated, so sometimes a different edited model will replace the model that was selected to be updated in the grid.
Thanks,
Rob
I ended up using the kendo grid datasource insert method to add any records returned by my controller that were not already in the grid. I did this in the RequestEnd event for the datasource.
In order for this to work for inline adds, I needed to make sure the first model in the list returned by the controller was always the model being added by the grid. For some reason the initial model being added does not have an ID until the dataBinding event is reached which occurs after the RequestEnd event. So on adds, I simply ignore the first model in the results because it is already in the grid.
Also, when editing rows that are manually inserted into the datasource and then cancelling the edit, the grid removes them from the datasource. I had to block this using the preventDefault() function in the DataBinding event when a "remove" action was encountered directly after editing a row that I manually inserted into the datasource.

Auto Load controller function to show data in a view - codeigniter

How can i Auto Load controller function to show data in a view?
Controller function, receive data from a model (query to the database).
And i want to show the info in the view, automatically.

How do I connect my backbone model to the view?

This is my first time with backbone and I am trying to figure out why console.logging this.model inside of my view doesn't spit out my model which has some default attributes.
Instead, I get:
function (){return a.apply(this,arguments)}
Here's my fiddle: http://jsfiddle.net/amit_e/muLjV/33/
(Please open your console to see the results)
What am I doing wrong? How do I get access to my model inside my view?
As View doesn't define a single model with model:Photo. Ideally, Model:Photo has to be defined in a collection.
You should create an instance of Photo inside View seperately. So, it will work.
When I added var myPhoto = new Photo(); in initialize block of view. I found this working then.
About usage of Collection:
Collection is a group of Models. So, You should define it anywhere in View ( Initialize or render or cutom function). More specifically, Collection
is used in MVC architecture to perform operation on models collectively. For example, In your case Album could be a collection of Photos.
You can store multiple instances on photo in Album. Album will be useful to you in operations like search, sort, add, delete of photos.

How do I send a message, at application launch, immediately after a core data entity is loaded?

The method applicationDidFinishLaunching:, is called in the app delegate prior to the loading of a Core Data entity into a table created with the "Core Data Entity" tool in the Interface Builder Library.
I have a custom view (with controller) that charts data based on the selected Core Data entity. When I launch my application, the top entry in the table of Core Data entities automatically is selected and other text fields bound to properties of that entity are populated with the correct data. I need to send a message to the custom view controller to redraw the custom view after the data is loaded at application launch.
Where should I put the code to send the message to the custom view controller? Is there a delegate method similar to applicationDidFinishLaunching: that receives a notification after the core data entity is loaded at launch?
It took me a while to figure this out since I'm relatively new to Cocoa. The appropriate documentation is here: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdBindings.html
If the "automatically prepares
content" flag (see, for example,
setAutomaticallyPreparesContent:) is
set for a controller, the controller's
initial content is fetched from its
managed object context using the
controller's current fetch predicate.
It is important to note that the
controller's fetch is executed as a
delayed operation performed after its
managed object context is set (by nib
loading)—this therefore happens after
awakeFromNib and
windowControllerDidLoadNib:. This can
create a problem if you want to
perform an operation with the contents
of an object controller in either of
these methods, since the controller's
content is nil. You can work around
this by executing the fetch "manually"
with fetchWithRequest:merge:error:.
You pass nil as the fetch request
argument to use the default request,
as illustrated in the following code
fragment.
I added an IBOutlet to my NSArrayController within the app delegate and connected it in Interface Builder. I then added the following to the method applicationDidFinishLoading: based on the documentation in the aforementioned link:
-(void)applicationDidFinishLaunching:(NSNotification *) aNotification {
NSError *error = nil;
BOOL ok = [myArrayController fetchWithRequest:nil merge:NO error:&error];
if (ok) {
[myCustomViewController redrawMyCustomView];
}
}
Now, when I launch the application, the data populates the table and the view automatically is redrawn with the selected data.

Resources