kendo-labs / kendo-backbone

Integrating Kendo UI with BackboneJS
Other
86 stars 31 forks source link

Change wrapper to keep the kendo and backbone model values identical #4

Closed pward123 closed 11 years ago

pward123 commented 11 years ago

Changing field values from either the Kendo or Backbone side now result in the other side being updated.

Adding and removing collection items from either the Kendo or Backbone side now result in the other side being updated

The model wrapper constructor now sets any unspecified fields to their default values.

mxriverlynn commented 11 years ago

Thanks for this, Paul! I'll be digging in to the Kendo UI + Backbone integrations a lot over the next few months, and will get this pulled in as soon as I can.

pward123 commented 11 years ago

Looks like I need to still do some adjusting on this code. Once I started using it with async loading of the backbone data, the handlingEvent flag related code started acting up.

I'll update the code as soon as I have it worked out.

On a side note, I'm planning on adding hooks in to allow the caller to perform transformation of the field values when copying between kendo/backbone. I'm thinking of adding optional toKendo toBackbone entries to the model wrapper's "field" hash. Comments?

pward123 commented 11 years ago

There are only two issues, that I know of, remaining with this pull. First, updating to the latest Kendo (2012.3.1315) and clicking "Edit", changing a field value and then clicking "Update" causes a stack exceeded crash. For now, I'm just leaving the 2012.1.322 version in place.

The real problem occurs when clicking "Edit", then "Cancel", then "Edit" again. The edit fields are empty.

When canceling an edit, the DataSource has to figure out what the record's attribute values should be reverted to. It uses an internal "pristine" array of unmodified data in order to do this. This pristine array is only populated during the success callback to the DataSource's call to the Transport's read function. Programmatically changing the records in the DataSource does not update this pristine data.

We cannot fix this by creating a new Transport class because there is no mechanism for Transport to inform the DataSource of changes to the underlying data.

The only way I can see to get around this problem is to extend DataSource itself. I'll take a stab at it and post the results later. The modified DataSource will be relying on undocumented, non-public implementation details of the DataSource class so buyer beware.

Edit: removed unnecessary opinionated comments =)

pward123 commented 11 years ago

After spending a lot of time working on the DataSource idea, it seems to me that what I have deviates dramatically from the idea behind this kendo-labs repo. IMO, the kendo-labs repo is simply a way to do everything in kendo and once you're done, you have a Backbone copy of the data. What I prefer to have is a Backbone application that uses a Kendo grid as a UI control.

Given the above, I think it is probably a better idea to cancel this pull request and place the new code in a separate repo. Therefore, I've moved the code into a new project at the following repo:

https://github.com/pward123/kendo-backbone-datasource

It still needs a lot of love (see my repo readme for the list of items not yet implemented). However, the demonstration functionality you have here all works flawlessly as far as I can tell in the new repo.