Search code examples
ember.jsember-datahandsontable

Ember Data and Handsontable recursion


When a Handsontable is instantiated, it calls a recursive method to build a data schema: https://github.com/handsontable/handsontable/blob/be8654f78ca84efc982047ca6b399e6c6d99f893/src/dataMap.js#L28, which in turns calls objectEach: https://github.com/handsontable/handsontable/blob/master/src/helpers/object.js#L235-L245

However, with an Ember Data record, it tries to iterate over properties like store, which means it gets caught in an endless loop.

Is there any way to bypass the recursiveDuckSchema method?


Solution

  • Unless Handsontable has some interface to allow pre-parsing data before it reaches the core of the plugin, I would say you may have better luck by transforming your ember-data models into something handsometable understands.

    let queryParams = //Your query params
    let data = this.get('getTheContent'); //Your models
    let handsomeData = data.map(function(item, index, enumerable)){
       return { id: item.get('id'), name: item.get('name'), other: item.get('other') }
    };
    // Result is [{id: 1, name: 'John', other: 'Other'}, {...}]