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

Models and IDs for rows #80

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
.build*
.build
*.lock
*.swp

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Misc #
############
.svn

# IDE #
#######
.settings
.idea
2 changes: 1 addition & 1 deletion lib/reactive_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
</thead>
<tbody>
{{#each sortedRows}}
<tr>
<tr data-id="{{getRowId}}">
{{#each ../fields}}
<td class="{{key}}">{{#if tmpl}}{{#with ..}}{{> ../tmpl}}{{/with}}{{else}}{{getField ..}}{{/if}}</td>
{{/each}}
Expand Down
22 changes: 19 additions & 3 deletions lib/reactive_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ var generateSettings = function () {
};
cursor.observe({added: addedCallback, changed: changedCallback, removed: removedCallback});
} else {
console.log("reactiveTable error: argument is not an instance of Meteor.Collection, a cursor, or an array");
console.error("reactiveTable error: argument is not an instance of Meteor.Collection, a cursor, or an array");
collection = new Meteor.Collection(null);
}
}
this._collection = this.collection;
this.collection = collection;

var fields = settings.fields || {};
if (_.keys(fields).length < 1 ||
Expand Down Expand Up @@ -179,6 +181,16 @@ Template.reactiveTable.getPageCount = function () {
return Math.ceil(count / rowsPerPage);
};

Template.reactiveTable.rendered = function () {
var collection = this.data.collection;
$(this.findAll('tbody tr')).each(function () {
var $row = $(this);
var id = $row.attr('data-id');
var model = collection.findOne(id);
$row.data('model', model);
});
};

Template.reactiveTable.helpers({
'generateSettings': generateSettings,

Expand All @@ -193,6 +205,10 @@ Template.reactiveTable.helpers({
return _.indexOf(fields, this);
},

'getRowId': function () {
return this._id;
},

'getKey': function () {
return this.key || this;
},
Expand Down Expand Up @@ -304,7 +320,7 @@ Template.reactiveTable.events({
var group = $(event.target).parents('.reactive-table-navigation').attr('reactive-table-group');
Session.set(getSessionRowsPerPageKey(group), rowsPerPage);
} catch (e) {
console.log('rows per page must be an integer');
console.error('rows per page must be an integer', e);
}
},

Expand All @@ -314,7 +330,7 @@ Template.reactiveTable.events({
var group = $(event.target).parents('.reactive-table-navigation').attr('reactive-table-group');
Session.set(getSessionCurrentPageKey(group), currentPage);
} catch (e) {
console.log('current page must be an integer');
console.error('current page must be an integer', e);
}
},

Expand Down