Draw each element of array in new row with DataTables (Meteor Tabular)

Philip O'Brien

I am using the Meteor Tabular package which implements DataTables. I am trying to create a table from a Mongo collection. The collection has one document of the form

{
  input: Array[365],
  output: Array[365],
  date: Array[365]
}

I define the table in Meteor with the following code

TabularTables.MyTable = new Tabular.Table({
    name: "MyTable",
    collection: MyTable,
    columns: [
        {data: "input", title: "Input", searchable: false},
        {data: "output", title: "Output", searchable: false},
        {data: "date", title: "Date", searchable: false}
    ],
    order: [[1, "desc"]],
    pageLength: 10
});

The problem is that when this is drawn, all 365 elements of each variable end up in a single cell, so I have one massive row. I want each element to be created in a separate row, i.e.

Input      Output      Date
input[0]   output[0]   date[0]
input[1]   output[1]   date[1]

whereas it is currently

Input            Output            Date
input[0...364]   output[0...364]   date[0...364]
Christian Fritz

You will need to transform your data and then put it into a local collection, since that package doesn't accept arrays (in contrary to what I thought earlier).

This seems to work:

TabularTables = {};
local =  new Meteor.Collection();

var data = MyTable.findOne();
if (data) {
    local.find().forEach(function(x) { local.remove(x._id) });
    for (var i in data.input) {
        local.insert({
            input: data.input[i],
            output: data.output[i],
            date: data.date[i]
        });
    }
}

TabularTables.MyTable = new Tabular.Table({
    name: "MyTable",
    collection: local,
    columns: [
        {data: "input", title: "Input", searchable: false},
        {data: "output", title: "Output", searchable: false},
        {data: "date", title: "Date", searchable: false}
    ],
    order: [[1, "desc"]],
    pageLength: 10
});

Note that this may no longer be reactive. But I'm assuming that your data in those big arrays is not going to change either, or else you would probably change your schema to be more compatible with meteor to begin with. So hopefully that's not a problem.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Updating array element in a collection in Meteor

分類Dev

Compresses each row of array

分類Dev

PHP append each element in an array

分類Dev

Push element at each index in an array

分類Dev

Count number of element for each row in a matrix

分類Dev

Adding new element to array in MongoDb

分類Dev

Create new tibbles for each element in a vector or column

分類Dev

Not have to create new element each time?

分類Dev

Datatables - How to stop the server side draw event when adding new data to table

分類Dev

PHP Adding an array element to each element in another array

分類Dev

Copying each row of matrix to a temporary array

分類Dev

How to append a value to each row of the array

分類Dev

Comparing array element to the next array and starting over when the element is new

分類Dev

Creating new array by inserting a new element to an existing array

分類Dev

Check if each element in a numpy array is in a separate list

分類Dev

Changing the attributes of each element of an object array

分類Dev

add value to each element of a multidimensional array

分類Dev

add value to each element of a multidimensional array

分類Dev

Changing the color of each element in a JSON array

分類Dev

How to compare each element of array to other elements?

分類Dev

Turn object into array, add object as new element

分類Dev

jQuery datatables row selectpicker

分類Dev

Find which interval row in a data frame that each element of a vector belongs in

分類Dev

Split every row in df and add value to each element

分類Dev

Python subtract first element from each respective row of matrix

分類Dev

Creating a new dataframe with many rows for each row in existing dataframe

分類Dev

Ignore columns containing zeroes in each row and create a new object

分類Dev

Ignore columns containing zeroes in each row and create a new object

分類Dev

Add a new column to dataframe and add unique values to each row

Related 関連記事

  1. 1

    Updating array element in a collection in Meteor

  2. 2

    Compresses each row of array

  3. 3

    PHP append each element in an array

  4. 4

    Push element at each index in an array

  5. 5

    Count number of element for each row in a matrix

  6. 6

    Adding new element to array in MongoDb

  7. 7

    Create new tibbles for each element in a vector or column

  8. 8

    Not have to create new element each time?

  9. 9

    Datatables - How to stop the server side draw event when adding new data to table

  10. 10

    PHP Adding an array element to each element in another array

  11. 11

    Copying each row of matrix to a temporary array

  12. 12

    How to append a value to each row of the array

  13. 13

    Comparing array element to the next array and starting over when the element is new

  14. 14

    Creating new array by inserting a new element to an existing array

  15. 15

    Check if each element in a numpy array is in a separate list

  16. 16

    Changing the attributes of each element of an object array

  17. 17

    add value to each element of a multidimensional array

  18. 18

    add value to each element of a multidimensional array

  19. 19

    Changing the color of each element in a JSON array

  20. 20

    How to compare each element of array to other elements?

  21. 21

    Turn object into array, add object as new element

  22. 22

    jQuery datatables row selectpicker

  23. 23

    Find which interval row in a data frame that each element of a vector belongs in

  24. 24

    Split every row in df and add value to each element

  25. 25

    Python subtract first element from each respective row of matrix

  26. 26

    Creating a new dataframe with many rows for each row in existing dataframe

  27. 27

    Ignore columns containing zeroes in each row and create a new object

  28. 28

    Ignore columns containing zeroes in each row and create a new object

  29. 29

    Add a new column to dataframe and add unique values to each row

ホットタグ

アーカイブ