meteor-tabular icon indicating copy to clipboard operation
meteor-tabular copied to clipboard

selector parameters

Open jdnichollsc opened this issue 8 years ago • 14 comments

Hi guys,

Thanks for this project! One question, can I use dynamic tables with the same table but using different selector?

What parameters does the selector receive?

TabularTables.ContractCompanies = new Tabular.Table({
  name: "ContractCompanies",
  collection: Companies,
  columns: [
    {data: "name", title: "Name"}
  ],
  "paging": false,
  "searching": false,
  "info": false,
  selector(params) {
    return { };
  }
});

Thanks in advance, Nicholls

jdnichollsc avatar Dec 01 '16 16:12 jdnichollsc

You could use Session or ReactiveVar to change params'

thearabbit avatar Dec 03 '16 09:12 thearabbit

@thearabbit thanks for your response, any example to do that?

jdnichollsc avatar Dec 03 '16 19:12 jdnichollsc

You could do this in Template

// HTML
{{> tabular table=TabularTables.Books selector=selector...........}}

// JS
Template.myTemplate.onCreated(function(){
   this.dataState = new ReactiveVar();
});
Template.myTemplate.helpers({
  selector() {
    return {author: Template.instance().dataState.get()};
  }
});

Template.myTemplate.events({
   'change ....'(event, instance){
      instance.dataState.set($(.....).val());
   }
}

thearabbit avatar Dec 04 '16 02:12 thearabbit

Beautiful! Works like a charm my friend! One question... It's possible to have multiple instances using the same Tabular Table instance but with different data? For example using Blaze.renderWithData =>

var data = row.data();
Blaze.renderWithData(Template.contractCompanies, data, $(row.child()[0]).find('td')[0]);

I have the following selector, but all tables show the same data at same time.

Template.contractCompanies.onCreated(function () {    
    this.companies = new ReactiveVar(this.data.companies);
});
Template.contractCompanies.helpers({
    selector: function(){
        var companies = Template.instance().companies.get();
        return {
            code : { $in: companies || [] }
        };
    }
});

And the template is:

<template name="contractCompanies">
    {{> tabular table=TabularTables.ContractCompanies selector=selector class="table table-striped table-bordered table-condensed"}}
</template>

Regards, Nicholls

jdnichollsc avatar Dec 04 '16 04:12 jdnichollsc

not clear, but I thinks that you could use Session instead.

// common
..... = new Tabular.Table({
  // other properties...
  selector(userId) {
    return { documentOwner: Session.get('data') };
  }
});

// Template
Template.A.onCreated(function(){
   Session.set('data');
});
.........
Template.B.onCreated(function(){
   Session.set('data');
});

And then remove session when template destroy.

thearabbit avatar Dec 04 '16 07:12 thearabbit

Doesn't work with session, because all tables are using the same template mmm

jdnichollsc avatar Dec 04 '16 19:12 jdnichollsc

could you try

// common
..... = new Tabular.Table({
  // other properties...
  selector(userId) {
    if(Meteor.isClient){
        return { documentOwner: Session.get('data') };
    }
  }
});

thearabbit avatar Dec 05 '16 00:12 thearabbit

@jdnichollsc, to properly handle reactive changes, you might want to use Template.currentData().companies instead of Template.instance().companies.get(), and you don't need the onCreated.

aldeed avatar Dec 06 '16 20:12 aldeed

Hi @aldeed, thanks for your help! But using currentData doesn't work :/ All the tables show the same data mmm

Check my code please =>

import { Template } from 'meteor/templating';
import './contractCompanies.html';

Template.contractCompanies.helpers({
    selector: function(){
        // var companies = Template.instance().companies.get();
        var companies = Template.currentData().companies;
        return {
            code : { $in: companies || [] }
        };
    }
});

Regards, Nicholls

jdnichollsc avatar Dec 06 '16 20:12 jdnichollsc

OK, it's hard to know what the issue is without a link to a small app that reproduces the issue.

aldeed avatar Dec 06 '16 20:12 aldeed

Let me create a small example please, thanks for all!

jdnichollsc avatar Dec 06 '16 20:12 jdnichollsc

@aldeed For the moment, check the following video please, is very odd => http://www.screencast.com/t/EssGAKcF9tO Thanks in advance, Nicholls

jdnichollsc avatar Dec 06 '16 20:12 jdnichollsc

@jdnichollsc Thanks, but we still would not be able to figure this out without a reproduction app.

aldeed avatar Dec 26 '16 16:12 aldeed

Hi @aldeed

Sorry for the delay, check the issue and the respective app to reproduce =>

issue tabular child rows

  • Project repository (tabular branch) => https://github.com/jdnichollsc/Meteor-Starter-Template/tree/tabular

Thanks in advance, Nicholls

jdnichollsc avatar Dec 26 '16 22:12 jdnichollsc