Meteor:reactiveTable adding data dynamically - meteor

I am using reactiveTable in my application:
table.html:
{{> reactiveTable collection=tables settings=tableSettings}}
How do I populate this table dynamically?

I found the answer. Did not realize tables is a reactive var.

Related

Meteor dynamic input fields

I'm looking for a way to create dynamic input fields in Meteor.js. I've chosen not to use Aldeed's Autoform for greater control over the code. From front end point of view I have no issues to add dynamic fields with +/- button to add and remove fields. What I'm struggling with is the insert statement on the back end. How can one add dynamic insert in Meteor.js? Cheers!
Essentially you need a reactive array of element that's rendered to the DOM via {{#each}} ... {{/each}}. When the array changes the DOM would re-render.
There's no need to create your own reactive array, there's one here with an example that does exactmy what you're asking for:
http://reactivearray.meteor.com/
However I'd recommend going one step further and using the ViewModel package for this (by the same author). Here's an example which shows how to use it to insert fields:
http://viewmodel.meteor.com/#contacts
Tim
Thanks Tim, these are both pretty useful. I'm using Collection 2 so decided to use objects ('object.$'). This is easy solution for me. cheers.

is there a way to do a meteor find() based upon more than one field?

Is there a way to do a meteor find (yes, it will be part of a publish function later, i'm just trying to test this)
that is filtered by more than one field at a time?
for example, let's say I only want to return those users who work at Disney in the IT department.
so far I have
Template.managerReports.disney = function () {
return employees.find({'company':"disney"});
};
//for template helper binding to
<template name="managerReports">
{{#each disney}}
<p>{{name}}</p>
{{/each}}
</template>
and attempts to add multiple comma-separated {field:value} pairs results very nicely in these ALSO being found and added to the disney results. I want to reduce results per added field. only data that matches multiple fields gets found.
am I being totally dumb? what is the usual meteor way to deal with multiple conditional finds?
If you want to find users who work for disney AND in the IT department:
employees.find($and: [{company: 'disney'}, {department: 'it'}]);
However, mongodb provides an implicit AND operation when specifying a comma separated list of expressions. So this is more commonly written as:
employees.find({company: 'disney', department: 'it'});
If you want to find users who work for disney OR in the IT department:
employees.find($or: [{company: 'disney'}, {department: 'it'}]);
You need to pass a javascript object, not comma-separated values:
Employees.find({
company: 'disney',
department: 'marketing',
salary: {$gt: 100000},
});

How to do some simple math in Meteor's template?

Let's say I have a simple product_orders collection in Meteor (_id, user_id, user_name, product_name, price_unit, quantity) and I want to show all orders of a single user in table where each row should contain:
user_name, product_name, quantity, price_unit, quantity, price_total (price_unit * quantity)
Additionally I would like to display a grand total for all user's orders.
I don't see easy way to do this in Handlebars.js template as Handlebars doesn't appear to support simple math operations. I can easily return product_order's cursor to my template but don't see easy way to calculate price_total and grand total in template.
I am thinking of creating a template helper of some sort but not sure if that's the proper direction to go. This problem looks like it must have a simple & elegant solution.
Yes, you should write a helper. Handlebars doesn't support using logic in the templates (which is a good practice as it forces you to apply the separation of concerns pattern).
A template helper looks like this:
Handlebars.registerHelper("grandTotal", function(user_name) {
var grandTotal = some_magic_to_calc_total(user_name);
return grandTotal;
});
Then you can call the helper like this from your template:
<template name="foo">
{{grandTotal user_name}}
</template>
You can read more about helpers in the Handlebars.js docs.

Displaying data with ASP.NET

I have a tbl_categories and a tbl_items. I want to display tbl_categories in a horizontal manner and list objects from tbl_items vertically below each category name. I am confused how to get all this data using TSQL stored procedures and displaying them using ASP.NET native controls.
Columns with headers of category names. rows of items keyed with category_id.
The db is set up correctly. It is the ASP.NET controls I have trouble with.
I would use a Repeater myself, and make it output an HTML Table. The categories row would be in the HeaderTemplate, the closing tags in the FooterTemplate, and the actual data inside the ItemTemplate
http://blogs.sitepoint.com/asp-net-repeater-control/
The best way to handle this is to setup business objects which support the data in a way you wish to present it, which may not always be the way it is handled by your database.
Then you can use those objects directly to bind or feed data into the UI.
You could use Pivot to do that. See this referece http://msdn.microsoft.com/en-us/library/ms177410.aspx

Asp.Net, Dynamic Data Website, Foreign key One to One relationship, DropdownList, how to customise?

I'm using Asp.Net's Dynamic Data Website project type.
I've created a db that has one to onerelationship between two tables specified using a foreign key, (this could be one to many but I've used the linq designer to change it to a one to one relationship).
i.e. I have a table Invoice and table CreditNote that takes an Invoice_Id as a foreign key
I was hoping that when I navigated to CreditNotes/Insert.aspx that it would display the a list of InvoiceIds in a dropdown list. It almost does this - it creates dropdownlist but only populates option value and not the text so I get something like this in the html source (notice only the value is populated - which looks empty to the user):
<select>
<option value="someInvoiceId"></option>
<option value="someInvoiceId"></option>
</select>
Can anyone tell me how I could fix this?
Thanks in advance for any help!
Hey I just stumbled over this question look for another answer but I think that you might need to set up some more meta data on your model such as the adding attributes so that you can define which field should be used
http://ericphan.info/blog/2009/2/24/aspnet-dynamic-data-display-custom-text-in-a-foreign-key-dro.html

Resources