DataTables 1.10

DataTables 1.10

EranEran Posts: 26Questions: 0Answers: 0
edited January 2013 in General
How stable is the version under:

https://github.com/DataTables/DataTables/blob/master/media/js/jquery.dataTables.js

Anyone got to test it yet ?
I really want to integrate DataTables 1.10 with Backbone js.....

Replies

  • EranEran Posts: 26Questions: 0Answers: 0
    edited January 2013
    .
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited January 2013
    It should be stable. I've not yet put in the biggest new feature - the new API, and I suspect that will be the part that introduces any significant issues that might need time to work on. So if you are going to grab it, I'd suggest doing it now (I'll be pushing work on the new API up to github by the end of the week - although I might branch it...).

    I don't know how you've been thinking about doing the integration with Backbone, but I'd certainly recommend using a combination of mData and mRender (the latter likely being a function).

    Allan
  • EranEran Posts: 26Questions: 0Answers: 0
    Hi Allan,

    In another discussion about DataTAbles 1.10 and Backbone js
    (http://www.datatables.net/forums/discussion/6302/dt-with-backbone.js#Item_22)
    you've wrote:


    "I've made the commit to the 1.10 development version that will not kill the binding, but I haven't done anything with actually experimenting with Backbone yet"


    Can you please explain how the binding is kept ?
    Will the table hold some kind of pointers to the Backbone js objects ?

    I've grabbed the 1.10 dev version but I'm waiting for your explanation before starting to test it.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > Will the table hold some kind of pointers to the Backbone js objects ?

    When you give DataTables an object in aaData (or fnAddData), previously DataTables would take a copy of it, thus breaking any links to the original object, which would obviously have screwed up trying to use Backbone objects (since the ones DataTables would use would be copies).

    DataTables no longer does that - this also has a performance benefit as well as RAM benefits.

    So the data used in aaData is the original data source - not a copy, and you'll be able to call methods, get properties etc from it as needed.

    Allan
  • EranEran Posts: 26Questions: 0Answers: 0
    Excellent.

    The fact that DataTables used to make a copy of the object pretty much killed the Backbone binding, but now I hope I'll finally get true binding between DataTable and my Backbone objects.

    I'll be testing it pretty soon and report back about my findings.

    Thanks :)
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Look forward to hearing how you get on! Also its not too late to put changes into 1.10 is they are fundamentally required. I'm thinking about extending mData / mRender to being able to call functions - for example: `mData: 'myFunc()'` as well as being able to use properties ( `mData: 'myProp'` ). You can use functions for that at the moment, but if you only need to call the function with no parameters, this might be an easier option.

    Allan
  • EranEran Posts: 26Questions: 0Answers: 0
    edited January 2013
    Hi Allan,

    I've just started to try out version 1.10 and ran into some problems.

    Let me explain what I've done so far and what I'm trying to achieve.

    Current state (1.9.4):
    *******************
    - My DataTable is getting via the aaData attribute my Backbone collection as JSON.
    Example: "aaData": books.toJSON()

    - Since there's no binding, when I update the model I have to re-render the whole table.


    Expected behavior (1.10);
    ***********************
    - According to my understanding, I can pass the object itself and not the JSON data ?
    Example: "aaData": books

    - If I update the object that I pass via aaData (my model) can the modified row be automatically re-rendered by the DataTables plugin ?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > - According to my understanding, I can pass the object itself and not the JSON data ?

    It still need to be an array of objects. What those object are don't really matter - but there much be an array with an item for each row of the table in it.

    > - If I update the object that I pass via aaData (my model) can the modified row be automatically re-rendered by the DataTables plugin ?

    If you tell DataTables that it needs to redraw - yes. There is no API to do that yet... I'm going to introduce new 'invalidate' methods in 1.10 for exactly this - but haven't yet done so.

    Allan
  • EranEran Posts: 26Questions: 0Answers: 0
    edited January 2013
    [quote]
    It still need to be an array of objects. What those object are don't really matter - but there much be an array with an item for each row of the table in it.
    [/quote]

    Backbone js uses 2 types of "entities":
    - Model - for a example a book object.
    - Collection - for a example a books object which is a collection of the object book.

    Both objects are complex ones - meaning a user can define a model's "fields" but the Backbone js library will add lots of attributes to the model / collection automatically (much like in a JPA entity proxy, if you are familiar with JPA).


    IMO, there are 2 ways to pass the data from a backbone js collection to the datatable plugin:

    1. As JSON which is basically a flat string (no object) in JSON format consisting of an array of objects. The problem here is that all Backbone's bindings are lost and your data is being held in 2 places: the Backbone js model / collection and your DataTables object.
    This is the way I'm currently passing my data.

    2. Passing the Backbone js collection object.
    This object will need to be processed in order to extract the required data.

    Maybe the plugin could convert the object to JSON when rendering....?
    I guess it's the most simple way to extract the data.
    When rendering on demand (when the model has changed) you take a "mirror" of the current data inside the model/collection (using .toJSON()) and use it for the redraw.


    [quote]
    If you tell DataTables that it needs to redraw - yes. There is no API to do that yet... I'm going to introduce new 'invalidate' methods in 1.10 for exactly this - but haven't yet done so.
    [/quote]

    So far I've "foreced" a redraw by emptying and refilling the table using fnAddData.
    But if there's a good binding in the plugin, I'd like the table to auto re-draw a specific row and not the entire table on a model change or at least allow me to redraw a specific row and not just the whole table.


    Let me know what you think......
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Ideally option 2 would be done, but it it would require DataTables (or more correctly, a plug-in) to have knowledge of how Backbone collections work. That's the route I'd like to take, and with invalidation options, I'm hoping it is possible to create just such a plug-in, but as I say, it isn't something I've had a chance to try yet.

    Allan
  • EranEran Posts: 26Questions: 0Answers: 0
    Putting Backbone js and binding aside, what about re-rendering a specific row ?

    For example, lets say I initialize the table "aaData": books.toJSON()

    Assuming my collection has changed, I want to be able to pass the changed collection (as JSON) and the table will only re-render the changed rows. Do you think it's possible to achieve ?
    (Assuming your table has a unique key, so you're able to detect a change by comparing the old row data with the new row data and decide if rendering is needed).
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > Assuming my collection has changed, I want to be able to pass the changed collection (as JSON) and the table will only re-render the changed rows. Do you think it's possible to achieve ?

    Yes - using fnUpdate . You pass in the changed data and DataTables will redraw with the new data.

    Allan
  • EranEran Posts: 26Questions: 0Answers: 0
    edited January 2013
    Alright. I'll give it a try.

    On another issue, I've made some changes to the dataTables 1.9.4 js file in order to support RTL (changes that can not be done in the css file).
    Would you like to review these changes ?

    If so, pleases send me your e-mail address and I'll e-mail you my modified file right away,
    You can use a simple compare / diff tool to view the changes.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    I'd certainly be interested to know what is required! allan @ - this site's domain name will get to me :-).

    Allan
  • EranEran Posts: 26Questions: 0Answers: 0
    edited January 2013
    Sent :)
This discussion has been closed.