0

I'm stucked into a problem that I need to pass my schema and my json to my constructor. First of all, I'm using Reactabular to develop a SPA, but in this library I can only start the application using a function that they have created called generateRows, but I have my own objects to inject, so I don't want to generate rows.

In my component i have this chunk of code:

class AllFeaturesTable extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      rows: generateRows(5, schema), 
      searchColumn: 'all',
      query: {}, // search query
      sortingColumns: null, 
      columns: this.getColumns(), 
      pagination: { 
        page: 1,
        perPage: 5
      }
    };

When I pass my rows as json object array everything works great untill I try to edit these values, and makes sense why i cannot edit this data. I can't because i didn't passed the schema(as you guys can see in the generaterows they took as parameter the schema).

My question is how can I achieve this? pass in my this.state.row the schema and my rows.

This is my rows:

const predefinedRows = [
   { "combustivel" : "Flex",
  "imagem" : null,
  "marca" : "Volkswagem",
  "modelo" : "Gol",
  "placa" : "FFF-5498",
  "valor" : 20000
  },
  { "combustivel" : "Gasolina",
  "imagem" : null,
  "marca" : "Volkswagem",
  "modelo" : "Fox",
  "placa" : "FOX-4125",
  "valor" : "20000"
  },
  { "combustivel" : "Alcool",
  "imagem" : "http://carros.ig.com.br/fotos/2010/290_193/Fusca2_290_193.jpg",
  "marca" : "Volkswagen",
  "modelo" : "Fusca",
  "placa" : "PAI-4121",
  "valor" : "20000"
  }

];

and this my schema :

const schema = {
  type: 'object',
  properties: {
    combustivel: {
      type: 'string'
    },
    imagem: {
      type: 'string'
    },
    marca: {
      type: 'string'
    },
    modelo: {
      type: 'string'
    },
    placa: {
      type: 'string'
    },
    valor: {
      type: 'integer'
    }
  },
  required: ['combustivel', 'imagem', 'marca', 'modelo', 'placa']
};

Thanks in advance!

Yuri Pereira
  • 1,945
  • 17
  • 24

1 Answers1

1

You should not use generateRows. generateRows introduced here, just return a dummy array data.

Just follow the example to implement your component. If you want to use all features, and pass to this.state.row the schema and rows. Just do this:

this.state = {
      row: {
        rows: yourRows,
        schema: yourSchema
      }, 
      searchColumn: 'all',
      query: {}, // search query
      sortingColumns: null, 
      columns: this.getColumns(), 
      pagination: { 
        page: 1,
        perPage: 5
      }
    };
fumihwh
  • 1,239
  • 7
  • 13