Reputation: 5244
I wish to create an editable table in meteor.
I have gone through the following links:
but not able to get anywhere, Am I looking in the right place?Please guide.I am new to meteor, any help would be appreciated.Thanks
Upvotes: 4
Views: 3433
Reputation: 105
I simply make an editable table using pure js and style it by bootstrap, Semantic UI or whatever you want. The following is my table row template
<template name="item">
{{#if editing}}
<tr>
<td><input type="text" id="editItemStore" value="{{store}}"></td>
<td><input type="text" id="editItemName" value="{{name}}"></td>
<td><input type="text" id="editItemWeight" value="{{weight}}"></td>
<td><input type="text" id="editItemWeightType" value="{{weightType}}"></td>
<td><input type="text" id="editItemQty" value="{{qty}}"></td>
<td><input type="text" id="editItemQtyType" value="{{qtyType}}"></td>
<td><input type="text" id="editItemPrice" value="{{price}}"></td>
<td><button class="saveItem">save</button><button class="cancelItem">Cancel</button>{{#each errors}}<div>{{message}}</div>{{/each}}</td>
</tr>
{{else}}
<tr>
<td>{{store}}</td>
<td>{{name}}</td>
<td>{{weight}}</td>
<td>{{weightType}}</td>
<td>{{qty}}</td>
<td>{{qtyType}}</td>
<td>{{price}}</td>
<td><button class="editItem">Edit</button><button class="deleteItem">Delete</button></td>
</tr>
{{/if}}
</template>
and the following is my row template events handler
Template.item.helpers({
editing: function(){
return Session.equals('editItemId', this._id);
}
});
Template.item.events({
'click .deleteItem': function(){
Items.remove(this._id);
},
'click .editItem': function(){
Session.set('editItemId', this._id);
},
'click .cancelItem': function(){
Session.set('editItemId', null);
},
'click .saveItem': function(){
saveItem();
},
'keypress input': function(e){
if(e.keyCode === 13){
saveItem();
}
else if(e.keyCode === 27){
Session.set('editItemId', null);
}
}
});
var saveItem = function(){
var editItem = {
store: $("#editItemStore").val(),
name: $("#editItemName").val(),
weight: $("#editItemWeight").val(),
weightType: $("#editItemWeightType").val(),
qty: $("#editItemQty").val(),
qtyType: $("#editItemQtyType").val(),
price: $("#editItemPrice").val()
}
Items.update(Session.get('editItemId'), {$set: editItem});
Session.set('editItemId', null);
}
please refer to this Complete Tutorial
Upvotes: 2
Reputation: 6020
I use meteor add olragon:handsontable
It works well. Check out the tutorials and docs.
Handsontable is a data grid component with an Excel-like appearance. Built in JavaScript, it integrates with any data source with peak efficiency. It comes with powerful features like data validation, sorting, grouping, data binding, formula support or column ordering. Built and actively supported by the Handsoncode team and the GitHub community , distributed free under the MIT license.
Upvotes: 1