GigaTables / reactables

GigaTables is a ReactJS plug-in to help web-developers process table-data in applications and CMS, CRM, ERP or similar systems.
MIT License
144 stars 30 forks source link

I want to give settings.ajax an object directly and not make an ajax call #61

Closed radugit closed 6 years ago

radugit commented 7 years ago

I want to give settings.ajax an object directly and not make an ajax call

I have added this function to Reactables.jsx ` isJson(item) { item = typeof item !== "string" ? JSON.stringify(item) : item;

  try {
      item = JSON.parse(item);
  } catch (e) {
      return false;
  }

  if (typeof item === "object" && item !== null) {
      return true;
  }

  return false;

} `

an try to make something like :

` if(this.isJson(this.settings.ajax)) { this.setLoader(columns.length); this.jsonData = this.settings.ajax; this.createTable(this.jsonData); this.setTableSort();

} else {
  //make the call to get json data
  fetch(this.settings.ajax).then((response) => ... in the build() function

`

I have managed to compile an index.js file a file with this modifications but when I compile my project I get : Uncaught (in promise) TypeError: E.forEach is not a function

Can you please add an option like this an option like this in the near future?

The reason that I'm asking for this option is that I don't always want to make and ajax call to get the json rows. Maybe I want to build an rows object on the fly and re-render the datatable with the rows object that I have created.

Thank you

radugit commented 7 years ago

Another thing that I will find useful will be: If I have some amounts in some column of the table, maybe I want to have the totals of those cells in the table footer

radugit commented 7 years ago

Never mind about giving settings.ajax an object directly and not make an ajax call, I made it myself. Moving on to add other features.

arthurkushman commented 7 years ago

Hi ragugit, glad to see u contributing with ideas as it develop our skills. Yes you can upload a file say with var data = require('./data.json'); Then u can even pass that data as <Reactables editor={editor} settings={settings} data={data}> Wonderful, then the user somehow need to make CRUD ops with that data - how can she do that? And what if it is not a nodejs server, but a script included in html page? Should we disable all CRUD buttons then?

Let's think about counters - yet it is good idea to count any int/double data column by demand for ex. via settings, but how to serve that functionality if there are 50, 75, 125 rows per page, counting only those showed? Probably those that total resulting?

PS just try to think through those proposals and complete the big picture, thx.

radugit commented 7 years ago

Hi, What I did is to test the settings.ajax and if it a object or a json (and not a link) to go ahead and create the table. This is good because if some how there are some changes made to the object or a json data you can reset settings.ajax and call setState again. I have also added custom classes on table header and on each cell in the body. Future plans include adding a footer to the table, and adding a custom event to know when the table got rendered. My time to work on this project is very limited but I'm not in a hurry thx

arthurkushman commented 6 years ago

As this question is to old, I'm closing it. Nevertheless, I've implemented the feature proposed here "If I have some amounts in some column of the table, maybe I want to have the totals of those cells in the table footer" - it is helpful in many accounting tasks, so thank u for the proposal.