material-table icon indicating copy to clipboard operation
material-table copied to clipboard

[BUG] - Columns.render props get called twice after exporting data and clicking on edit

Open francesco-clementi opened this issue 7 years ago • 0 comments

I have a custom render function for a column and a custom export function for data in a editable table.

When I click on export data and then on edit, all rows call the render function twice.

columns.render: render: rowData => rowData[i] ? rowData[i]+"%" : ""

export function: `exportCsv: (columns, data) => { _.each(data, item => { return _.each(item, (i, key) => { if(key.startsWith("201")){ _.extend(item, {[key]: i+" %"}) } }) })

        const fields = _.pluck(columns, 'field');
        const opts = { fields };

        try {
          const csv = parse(data, opts);

          let csvContent = "data:text/csv;charset=utf-8,"
              + csv
              var encodedUri = encodeURI(csvContent);
              var link = document.createElement("a");
              link.setAttribute("href", encodedUri);
              link.setAttribute("download", `${moment().format('YYYY-MM-DD')}_allocation.csv`);
              document.body.appendChild(link);
              link.click()
        } catch (err) {
          console.error(err);
        }
      }
    }}`

Column rendered at the start: image

Column rendered after exporting and clicking on edit: image

Everytime that I export the data and then click on edit, the render function get called 2,3,4 ecc... times.

francesco-clementi avatar Sep 12 '19 09:09 francesco-clementi