angularjs ng-grid computed column - angularjs

I'm trying to emulate a spreadsheet using AngularJS and ng-grid. My needs are simple but I cannot find anything anywhere that will help me fix my code.
I have a simple table of scores and in the last column I need a "Total Score" column.
You can see my code at this plunk.
My problem is that though I was able to get the total in each row on document.load, I cannot make the "Total" column update whenever any of the scores are changed.

Or alternatively, you could add the getTotal() function directly to the model object:
http://plnkr.co/edit/LhlK1C?p=preview
I prefer solutions where I don't have to work with $watch(), but it depends if you want the total to be stored in your model or only need it for display.

You could watch for changes to the 'original_data' object and recreate the process_data object every time updates.
http://plnkr.co/edit/c4iynItnznKNRoFgeuio?p=preview

Related

Need a way to query MongoDB collection, and ngRepeat beginning at specific point

is there a way to query a MongoDB collection, return the results, use an AngularJS ng-repeat to iterate through the results, BUT BEGIN the iteration at a specific position in the results, somewhere in the middle for example?
I am currently returning a query to an angular view; a category of materials. Then i have my view set up to paginate(ng-repeat) through the results. However, no matter what material I click on to bring me into the view (from a different view), the ng-repeat always starts at the beginning of the materials list, rather than on the material i clicked. Any thoughts?
I do not believe the mongodb part has anything to do with the actual question but ill give you 2 options:
The quick way:
<div ng-repeat="item in items" ng-show="$index >= myCtrl.startPoint">
While this will do the trick you might want to do the ng-show expression with a filter. In addition you might run into performance issues. You should also use the track by feature.
A better way would be to have a filteredData model for the ng-repeat and do the correct filtering once per action. You would have to make sure yourself that the model is updated on every data change and every user input.
There are many choices in between these 2 options but what to use depends on your needs. For instance - does user input change frequently? Is your data updated frequently? etc.

How developers can assign Unique Id for HTML Controls in Grid which can used by Automation Test tool like Code UI?

I am using Angular JS - ng-table. Which generates grid structure with Sorting, filtering, pagination features.
We are using Coded UI automation tools which expects all HTML controls should be Unique.
For Example :
Lets have Grid Table consist of Employee records.
Automation Tester wrote a test cases expecting the first 1-10 records are having unique Id (Emp1-to-Emp10) which is NOT going to be changed.
But when Tester sorting the Grid then whole structure of Grid is being changed.
First 10 records will have - Emp11,Emp1,Emp4,Emp5,Emp37,Emp42,Emp67,Emp89,Emp12,Emp10.
when the Tester re test the test case it FAILs .
So, how to maintain the consistency for dynamic records unique ids with the combination of Angular JS + Coded UI?.
Thanks
Gokul
I would say that what is happening is expected sorting behaviour..
Some ways that you could solve your problem. From the tester's point of view:
Tests should restore the page to the initial state before ending. For example if the test sorts a table, it should 'un-sort' the table before it finishes. This leaves the data in an expected state so that the test can be repeated
Don't select things by id. All the test frameworks I know of allow you to select things by css selectors, which can do much more powerful selections than by id. E.g. you could look up a row by the employee Id and it would find it regardless of what order the table is in.
From the developer's point of view:
I presume the rows are items in an array. You can assign a unique id as a property to each item in the array and use it in the template markup. The unique id would not be affected by any sorting.
Unless you are using a very unusual framework or constrained by strange rules, I would suggest that the automated tests are amended rather than the code.

How to save child properties?

Breeze & Angular & MV*
I get an invoice object and expand it's necessary properties: Customer, Details, etc.
To access detail properties is easy, invoice.detail[n].property. And saving changes to existing properties (1 - n) is also easy. In my UI, I simply loop through my object vm.invoice.details to get & display all existing details, bind them to inputs, edit at will, call saveChanges(), done!
(keep in mind, in this UI, I need to complete the following too....)
Now, I have blank inputs for a new detail I need to insert.
However, I need to insert a new detail into the existing array of invoice details.
For example: invoice #5 has 3 details (detail[0], detail[1], detail[2]). I need to insert into this existing invoice, detail[3], and call saveChanges()
I've tried to call the manger.createEntity('invoice') but it complains about FK constraints. I know you can pass values as a second argument in createEntity('obj', newvalues)...but is that the correct and only method?
Seems like this should all be much easier but, well, I am at a loss so, please help where you can. TIA!
Take a look at the DocCode sample which has tests for all kinds of scenarios including this one.
Perhaps the following provides the insight you're looking for:
function addNewDetail() {
var newDetail = manager.createEntity('Detail', {
invoice: vm.currentInvoice,
... other initial values
});
// the newDetail will show up automatically if the view is bound to vm.details
}
Notice that I'm initializing the parent invoice navigation property. Alternatively, I could just set the Detail entity's FK property inside the initializer:
...
invoiceId: vm.currentInvoice.id,
...
Either way, Breeze will add the new detail to the details collection of the currentInvoice.
Your question spoke in terms of inserting the new Detail. There is no need to insert the new Detail manually and you can't manage the sort order of the vm.currentInvoice.details property any way.
Breeze has no notion of sort order for collection navigation properties.
If you need to display the details in a particular order you could add a sorting filter to your angular binding to vm.currentInvoice.details.
Make sure you have correct EntityName, because sometimes creating entity is a not as simple as it seems.Before working with entities see
http://www.getbreezenow.com/documentation/creating-entities
I will suggest you to look ur metadata file, go to last line of your file, you can see the field named "entitySet"
"entitySet":{"name":"Entity_Name","entityType":"Self.Entity_Name"}
check the entityName here i took as "Entity_Name" and then try to create the entity and use this name
manger.createEntity('Entity_Name');

AngularJS - Is it possible to show data in a specific time range?

hope someone can help me with this question.
I have an entity which contains a start time (let's say 15 o'clock) and an end time (let's say 16
o'clock). It also contains the date (let's say today^^).
So my query returns all data of today, but I only want to show the data between 15 and 16 o'clock.
Do I need to set a $timeout for each object? Or is it possible to automatically call a method called shouldShowData which used in ng-show?
Basically I have a list of objects and want to show single object just on a specific time of the day.
EDIT
Imagine that the screen is shown in a public place and displays different news at different time (morning news, evening news, ...) and should automatically update when the specific news should be displayed based on it's start and end time. It can't be updated manually with a refresh button for example.
Great to here from you :)
I have found similar problem and solution for it here
All you need is to wrap this into $filter and use on ng-repeat.

Dynamically set Grouping in ng-table

I am using ng-table to list a set of elements, and am needing to group the elements in the table.
I want to be able to redefine what the data is sorted by, (even if this means having to redefine the table), as the creation of the table is fast.
I have had a go on JSFiddle, but it doesn't seem to be able to update the grouping.
I aim to have something like the following:
1. create table using initial data, and default grouping column
2. change grouping column using a variable
3. table updates to reflect changed grouping variable
I thought of maybe using an ng-if to surround the entire ng-table, as I've read that it destroys the DOM elements inside it when evaluated to false, but this is a drastic measure to something that may be fairly easy to solve.
Link to JSFiddle
I found what I was looking for.
See the updated JSFiddle here.
What I had to do was call the $scope.tableParams.reload() function.
I didn't find any documentation about this, and ended up looking through the source code.
JSFiddle Link

Resources