Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7555151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:31:44+00:00 2026-05-30T11:31:44+00:00

I’m trying to make a dynamic sales report that allows users to remove customer

  • 0

I’m trying to make a dynamic sales report that allows users to remove customer rows from a table via some soon-to-be-made UI. The totals row, representing the total of all products sold, needs to be updated for the removal of a customer from the display.

The code (at bottom of post) initially shows this:

product1:customer1 5
product2:customer1 6
product3:customer1 7
product1:customer2 5
product2:customer2 6
product3:customer2 7
product1:customer3 5
product2:customer3 6
product3:customer3 7
product1- 15
product2- 18
product3- 21

Then I use the console to execute the line: Report.cellsController.toggleCustomerDisplay('customer2');

What I EXPECT is:

product1:customer1 5
product2:customer1 6
product3:customer1 7
product1:customer2 0
product2:customer2 0
product3:customer2 0
product1:customer3 5
product2:customer3 6
product3:customer3 7
product1- 10
product2- 12
product3- 14

What I GET is:

product1:customer1 5
product2:customer1 6
product3:customer1 7
product1:customer2 0
product2:customer2 0
product3:customer2 0
product1:customer3 5
product2:customer3 6
product3:customer3 7
product1- 15
product2- 18
product3- 21

When I run the debug function Report.totalsController.spillguts() I am told that the expected values are there – so why isn’t my view being updated?

Code:

<html>
  <head>
    <link rel="stylesheet" href="assets/bpm_styles.css" type="text/css" media="screen" charset="utf-8" />

    <title>my_app</title>


    <script type="text/x-handlebars" data-template-name='sales-report'>
        {{#each Report.cellsController}}
            <div>{{productID}}:{{customerID}} {{quantity}}</div>
        {{/each}}
        {{view Report.TotalProductsView}}
    </script>

    <script type="text/x-handlebars" data-template-name='total-products-report'>
        {{#each Report.totalsController}}
            <div>{{keyValue}}- {{quantity}}
        {{/each}}
    </script>

  </head>
  <body>
    <h1>Hello World</h1>
  </body>

  <script type="text/javascript" src="assets/bpm_libs.js"></script>
  <script type="text/javascript">
        spade.require('my_app');
        spade.require('ember');

        var Report = Em.Application.create();
        /**************************
        * Models
        **************************/
        Report.CustomerProductReportCellModel = Em.Object.extend({
            productID: '',
            customerID: '',
            originalQuantity: 0,
            display: true,

            quantity: function() {
                var display = this.get('display'),
                    originalQuantity = this.get('originalQuantity');

                return display ? originalQuantity : 0;
            }.property('display', 'originalQuantity')
        });

        Report.CustomerProductReportTotalCellModel = Em.Object.extend({
            primaryID: 'productID',
            keyValue: '',
            quantity: function(){
                var content = Report.cellsController.get('content');
                var currentDisplayQuantity = 0;
                var keyValue = this.get('keyValue');
                var primaryID = this.get('primaryID');

                content.forEach(function(cell){
                    if(cell[primaryID] == keyValue){
                        var qty = cell.get('quantity');
                        currentDisplayQuantity += qty;
                    }
                });

                return currentDisplayQuantity;
            }.property('Report.cellsController.content', 'keyValue', 'primaryID')
        });

        /**************************
        * Controller
        **************************/

        Report.cellsController = Em.ArrayController.create({
            content: [],
            createCellFromObjectLiteral: function(objLiteral) {

                var ourCell = Report.CustomerProductReportCellModel.create(objLiteral);
                this.pushObject(ourCell);
            },
            spillguts: function() { //for debugging purposes
                var content = this.get('content');
                content.forEach(function(cell){
                    //$('#debug').innerHTML += 
                    alert(cell.productID + ' ' + cell.customerID + ' ' + cell.originalQuantity + ':' + cell.get('quantity') + '<br />');
                });
            },

            toggleCustomerDisplay: function(customerID){
                var content = this.get('content');
                content.forEach(function(cell){
                    if(cell.get('customerID') == customerID){
                            var toggleToValue = !cell.get('display');
                            cell.set('display',toggleToValue);
                    }
                });
            }

        });

        Report.totalsController = Em.ArrayController.create({
            content: [],
            createTotalFromObjectLiteral: function(objLiteral) {
                var ourTotal = Report.CustomerProductReportTotalCellModel.create(objLiteral);
                this.pushObject(ourTotal);
            },
            spillguts: function() { //for debugging purposes
                var content = this.get('content');
                content.forEach(function(cell){
                    alert(cell.keyValue + ' ' + cell.get('quantity'));
                });
            }
        });

        //customer 1
        Report.cellsController.createCellFromObjectLiteral({productID: 'product1', customerID: 'customer1', originalQuantity: 5, display: true});
        Report.cellsController.createCellFromObjectLiteral({productID: 'product2', customerID: 'customer1', originalQuantity: 6, display: true});
        Report.cellsController.createCellFromObjectLiteral({productID: 'product3', customerID: 'customer1', originalQuantity: 7, display: true});

        //customer 2
        Report.cellsController.createCellFromObjectLiteral({productID: 'product1', customerID: 'customer2', originalQuantity: 5, display: true});
        Report.cellsController.createCellFromObjectLiteral({productID: 'product2', customerID: 'customer2', originalQuantity: 6, display: true});
        Report.cellsController.createCellFromObjectLiteral({productID: 'product3', customerID: 'customer2', originalQuantity: 7, display: true});

        //customer 3
        Report.cellsController.createCellFromObjectLiteral({productID: 'product1', customerID: 'customer3', originalQuantity: 5, display: true});
        Report.cellsController.createCellFromObjectLiteral({productID: 'product2', customerID: 'customer3', originalQuantity: 6, display: true});
        Report.cellsController.createCellFromObjectLiteral({productID: 'product3', customerID: 'customer3', originalQuantity: 7, display: true});

        //Product Totals
        Report.totalsController.createTotalFromObjectLiteral({primaryID: 'productID', keyValue: 'product1'});
        Report.totalsController.createTotalFromObjectLiteral({primaryID: 'productID', keyValue: 'product2'});
        Report.totalsController.createTotalFromObjectLiteral({primaryID: 'productID', keyValue: 'product3'});

        //alert(Report.totalsController.get('content')[1].get('quantity'));

        Report.MainView = Em.View.extend({
            templateName: 'sales-report'
        });

        Report.TotalProductsView = Em.View.extend({
            templateName: 'total-products-report'
        });

        //Report.mainView.append();

        var mainview = Report.MainView.create();
        mainview.append();

        //var totalproductsview = Report.TotalProductsView.create();
        //totalproductsview.append();
  </script>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:31:45+00:00Added an answer on May 30, 2026 at 11:31 am

    I see what you’re trying to do, but there are some violations in here. Namely your models should not have hard coded controllers in them. That goes against MVC design patterns. Another is that you should be using .set() when creating your controllers.

    I rewrote your code and put a working solution in this jsFiddle. Hope that clears things up for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.