Datatables + Ember Data

Datatables + Ember Data

dragossdragoss Posts: 1Questions: 0Answers: 0
edited March 2014 in General
Hello,

Is there any way to import data from the Ember Data Store into the datatables and still provide functionality like pagination, sorting and searching like on server-side processing? I obtain my data via Ember Data from a server and populate the store. I would like to be able to process it client side, via controllers, and pass it back to datatables. The problem is if datatables can pass the same data it passes to a server, but to Ember? A working example can be seen here: http://jsbin.com/oJIzIlO/34/edit.

Thank you,
Dragos

Replies

  • ohmygoshjoshohmygoshjosh Posts: 1Questions: 0Answers: 0

    I realize this question was asked 5 months ago, but I just answered this myself.

    My solution was to dynamically get my model data from the Ember Data Store, convert it to a standard array of JSON objects, and dynamically feed it into the DataTable. Here's some code:

    var locations = this.get('isShowActiveLocations');
    
    var json = locations.map( function( myModel ) {
        return myModel.toJSON();
    });
    
    var table = $('#locationsTable').dataTable();
    table.fnClearTable();
    if ( json.length && json.length > 0 ) {
       table.fnAddData( json );
    }
    

    I still need to figure out how dynamically pass in links to rows, though. For example, by the time dataTable renders, Handlebars has already rendered all {{link-to}} helpers, so this gets passed through as a string literal.

    I can probably do this by defining a function which returns an Ember view, but that seems a little clunky.

    Josh

This discussion has been closed.