Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some newb questions #27

Open
landland opened this issue May 23, 2014 · 5 comments
Open

Some newb questions #27

landland opened this issue May 23, 2014 · 5 comments

Comments

@landland
Copy link

Hi there, I have some simple questions that I haven't been able to figure out with this package.

question 1. In the normal Meteor way, I'd publish a collection like this (sorry I don't know coffeescript)

Meteor.publish('profiles', function(listId) {
    check(listId, Match.Optional(String));
    return Profiles.find({
            listId: listId
        }
});

but what is the equivalent with dataTables if I wanted to pass in a listId? Just from the example, I have the following that returns all collection items rather than a subset since I am not adding listId to the query.

// how do I add {listId: listId} ?
var ProfileList2 = new DataTableComponent({
    id: "ProfileList2", // <--- what is id in this case? 
    subscription: "profileList2",
    collection: Profiles
});
ProfileList2.publish();

question 2. I have a table that has returned, but some columns are blank. I think it has to do with the nested object structure. So if I have a Profile with a name at "contact.name" that column returns blank.

profiles: function() {
        return {
            columns: [{
                title: "Name",
                data: "contact.name" // this column is blank, am I doing this incorrectly?
            }, {
                title: "Emails",
                data: "email" // this column is ok and returns the email address as desired
            }],
            subscription: "profileList2" 
        };
    }

I hope I am clear. Let me know if it doesn't make sense, thanks for any help.

@gjolund gjolund self-assigned this May 23, 2014
@gjolund
Copy link
Contributor

gjolund commented May 29, 2014

@landland sorry for the late response, thought I already answered this, but I guess it was just in my imagination.

Question 1

You can limit the data set published by the DataTable component on the server by specifying a query parameter.

On the server :

RowsTable = new DataTableComponent
    subscription: "rows"
    collection: Rows
    # ##### Only return the rows created today
    query:
      createdAt: $gte: moment().startOf( "day").toDate()

  RowsTable.publish()

Or if you need access the the publication context ( to check the userId for example ) use a function for the query property.

RowsTable = new DataTableComponent
    subscription: "rows"
    collection: Rows
    debug: "userId"

    # ##### Only return rows this user owns
    query: ( component ) ->
        component.log "userId", this.userId
        return { owner: this.userId }

  RowsTable.publish()

You can also define a query on the client, which will let you limit the subscription even further.

This way you can have a general subscription that publishes data for several tables, and then the tables can limit the data further for their needs.

Question 2

Accessing nested properties has been working fine for me and a few other users, but I will take a second look as soon as possible. To help me isolate the problem can you put together a small example the replicates the issue?

I believe the issue may not be the DataTable but instead the publication that is providing the data, and that perhaps the nested properties are not being published?

Whatever the case, being able to replicate the issue quickly will really help speed things along.

  • Austin

@gjolund gjolund added bug and removed bug labels May 29, 2014
@ephemer
Copy link

ephemer commented Jul 3, 2014

Hi Austin and @landland! I'm having the same two issues. Did you figure out what was going on? I've never worked with the standard (non-meteor) jquery datatable, so some of this is still magic to me.

I got the data table working for properties of the base object (a Meteor.user) but I can't seem to get any nested data (see columns below) into the data tables. The jquery-datatables debug: "all" gives me the following output for one of the users:

1: Object
_id: "3bkGbxxxxiHcg43"
createdAt: Sat Jun 07 2014 17:17:28 GMT+0200 (CEST)
emails: Array[1]      // Actually does contain the data I need! But doesn't fill talbe
emails.0.address: "" // this property doesn't exist - it should be looking up within the array above
emails.0.verified: ""
profile: Object        // Again: contains what I'm looking for
profile.realname: "" // Property doesn't actually exist in my database
role: "user"

This is in my template:

<div class="datatable">
    {{> DataTable users_datatable }}
</div>
Template.UsersIndex.users_datatable = function () {
    return {
        debug: "all",

        // ## Columns
        //  * Map your dataset to columns you want displayed
        columns: [
        {
          title: "Role",
          data: "role" // works
        },{
          title: "Email Address",
          data: "emails.0.address" // broken
        },{
          title: "Verified",
          data: "emails.0.verified"
        },{
          title: "Real Name",
          data: "profile.realname"
        },{
          title: "Member Since",
          data: "createdAt", // works!
          mRender: function ( data, type, row ) {
            return moment( data ).fromNow(); // data = row.createdAt
          }
        }],

        // ## Subscription
        //  * the __datatables__ publication providing the data on the server
        subscription: "users_index",

    };
};

And then on the server:

UsersIndex = new DataTableComponent({
    subscription: "users_index", // what it will be published as
    collection: Meteor.users,    // where the data is coming from
    /*query: { // find query
        'createdAt': 1,
        'emails': 1,
        'profile': 1
    }*/
})
.publish();

I realised my problem with the server-side query is that it's looking for the specified values, rather than only returning certain fields. Is it possible to specify only certain fields to return? That would speed up the queries a lot.

Can you point me to where the dot notation gets turned into subobjects? Thank you for your time.

@maxko87
Copy link
Contributor

maxko87 commented Aug 26, 2014

ephemer -- did you find a solution to this problem? I would also like to publish only selected fields to the client via datatables.

@ephemer
Copy link

ephemer commented Aug 27, 2014

Hi Max,

The solution I went with in the end was a custom one (my workmate and I wrote our own wrapper). It works surprisingly well: it takes any standard cursor you give it (you choose the fields), it's clean, reactive, and FAST (instantaneous) for our uses (a few thousand records each table). It doesn't access the server for display filter or sort requests.

We're in a busy period until mid September but at that point I'd strongly consider open-sourcing our version. Interest from you and others would obviously help to motivate that move.

Cheers,

ephemer

On Wed, Aug 27, 2014 at 12:15 AM, Max Kolysh [email protected]
wrote:

ephemer -- did you find a solution to this problem? I would also like to publish only selected fields to the client via datatables.

Reply to this email directly or view it on GitHub:
#27 (comment)

@ephemer
Copy link

ephemer commented Sep 1, 2014

@maxko87 I've open sourced what we came up with. Any feedback is welcome and encouraged!
https://github.com/ephemer/meteor-reactive-datatables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants