aslagle / reactive-table

A reactive table designed for Meteor
https://atmospherejs.com/aslagle/reactive-table
Other
328 stars 137 forks source link

Collection as array, table doesn't update #424

Closed robomatic closed 6 years ago

robomatic commented 8 years ago

My collection array collection.find().map(function(row) { do stuff return row}), starts out empty then is populated but reactive table doesn't update.

Template.DataTable.helpers({
    instance() {
        return Template.instance();
    },
    rTableConfig() {
        const instance = Template.instance();
        const query = instance.Collection.constructViewQuery(instance.terms);
        const collection = instance.Collection.find(query.find).map(function(row) {
            if (typeof row._id === 'object') {
                // fixes id's created outside of meteor
                row._id = row._id._str;
            }
            if (typeof instance.dataTransform === 'function') {
                row = instance.dataTransform(row);
            }
            return row;
        });
        console.log(collection);
        instance.rTableConfig = _.extend(instance.rTableConfig, {
            rowsPerPage: instance.state.get('pageLength'),
            showFilter: false,
            noDataTmpl: Template.RTableNoData,
            collection: collection,
            showNavigation: 'never'
        });
        return instance.rTableConfig;
    }
});

collection console log returns [] then [{_id: "663zMxMNqS48TgAKg" ... other fields }]

any idea what's going on?

sourabh-shankar commented 8 years ago

I think you populating the reactive table using array data not "cursor". AFAIK, arrays are not reactive by nature in meteor.

robomatic commented 8 years ago

Yes that's true but the rTableConfig helper is reactive and should rerun the whole reactive table template.

aslagle commented 8 years ago

I'm not sure what's going on either, it's supposed to set up the table again if the template data has changed.

MMrj9 commented 6 years ago
    return {
      collection: instance.products.get(),
      showFilter: false,
      showNavigationRowsPerPage: false,
      rowsPerPage: instance.pageSize,
.....
}

This works for me, I removed the .get()