Ng2-smart-table: is possible to pass data rows without keys?

1k views Asked by At

I want to pass to my data table some values as rows, like the following:

["ab", "b", "c"]. So, my json is just an array that doesn't have any keys, just a value. I know that we need to have a keys for each element that is the same of the column, but is there any solution? thanks

1

There are 1 answers

0
wrager On

According to the documentation, the type of table row data can only be object. You can convert raw data, for example, like this:

// We should know the columns order
var columns = ['id', 'name', 'username', 'email'];

var data = rawData.map(function(item) {
  return item.reduce(
    function(result, item, columnIndex) {
      result[columns[columnIndex]] = item;
      return result;
    },
    {}
  );
});

https://jsfiddle.net/jLwmhbwv/