简体   繁体   中英

Calling row in Meteor Tabular

TabularTables.Transactions = new Tabular.Table
  name: "Transactions"
  collection: Transactions
  responsive: true
  columns: [
    {
      data: "transactionOperation"
      title: "Operation"
    }
    {
      data: "sum"
      title: "Sum"
      render: (val, type, doc)->
        if doc.transactionOperation == "Credit"
         return "- " + val
        else
         val
    }
  ]

I have this tabular set up for the meteor using TabularTables.

In the render function there are val, type and doc. Doc is the information of the whole entry in the database. However, if I do not specify it in the columns, it does not return. For example I remove the

{
      data: "transactionOperation"
      title: "Operation"
    }

portion, the logic in the render if doc.transactionOperation == "Credit" is never true, because doc.transactionOperation is not set. Console.log(doc) shows that the object has only the Sum attribute.

Is there a way for it to return the full row instead of only the columns specified?

Take a look at extraFields property. That should work in your case.

 TabularTables.Transactions = new Tabular.Table({
  name: "Transactions"
  collection: Transactions
  extraFields: ['transactionOperation']
  /* columns go here
  */
 });

By adding fields to extraFields property those get published and you can retrieve from the doc variable in the render function.

Here is the official documentation for that.
https://github.com/aldeed/meteor-tabular#publishing-extra-fields

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM