Git Product home page Git Product logo

backgrid-sum's Introduction

backgrid-sum (v0.1.6)

Step 1)

var col = new Backbone.Collection(
  [
    { name: '10.95', value: '15.50' },
    { name: '15.50', value: '20.75' }
  ]
);

var grid = new Backgrid.Grid({
  columns: [
    { name: 'name', label: 'Name', editable: false, cell: 'string' },
    { name: 'value', label: 'Value', editable: false, cell: 'string' }
  ],
  collection: col,
  row: window.Backgrid.SummedRow.extend({ columnsToSum: ['name', 'value'], multiplier: 'multiplier' }),
  body: window.Backgrid.SummedColumnBody.extend({ columnsToSum: ['name', 'value'] })
});

document.body.appendChild(grid.render().el);

Step 2)

???

Step 3)

profit

Summing the cells of a row

To sum the cells of a row, you'll want to override the row option in Backgrid.Grid, like so:

var grid = new Backgrid.Grid({
  ...
  row: window.Backgrid.SummedRow.extend({ columnsToSum: ['name', 'value'], multiplier: 'multiplier' })
});

Summing the cells of a column

To sum the cells of a column, you'll want to override the body option in Backgrid.Grid, like so:

var grid = new Backgrid.Grid({
  ...
  body: window.Backgrid.SummedColumnBody.extend({ columnsToSum: ['name', 'value'] })
});

Parameters

columnsToSum

columnsToSum is optional. If omitted, all columns will be summed.

multiplier

multiplier is optional. It can be a Number, or it can be a String representing the name of the column.

Installing with bower

Add "backgrid-sum": "~0.1.6" to the dependencies section of your bower.json.

Using lodash instead of underscore

If you're using lodash, just override the dependencies in your bower.json:

"overrides": {
  "backgrid-sum": {
    "dependencies": {
      "lodash": "*",
      "backbone": "~1.1.0",
      "jquery": "~2.0.3",
      "backgrid": "~0.3.5"
    }
  }
}

backgrid-sum's People

Contributors

briandrum avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.