Copying the row of table in react - javascript

Hi I have a reqirement in react. I need to copy the row of table in UI. means once user clicks on the highlighted icon in yellow in below image. the same row should be duplicated .
Could you guide me , how can I approach for the same?
so the below row should appear twice.

If you have the object that represents the row then just push the same into the array that consists of all this rows
array.push(clickedrow);
And let this array be a state so when you change it will rerender and you can see the updated list on UI.

Related

Restrict adding multiple blank rows in tabulator

I am using tabulator in Angular.I wanted to add new blank row on a button click,
so I am adding a new row by using this.table.addRow({});
But every time I click on button, its adding blank row. But I don't want multiple blank rows to be added in Table.
Can I prohibit adding blank row if already one blank row is added?
How I can find out number of blank rows in table ?
Tabulator itself has no concept of a "blank row" all, rows are just objects and the table will visualize the data contained in those objects.
But you could use the searchRows function with a custom filter to retrieve the empty rows and check this before triggering the addRow function:
var emptyRowCount = table.searchRows((data) => { return Object.keys(data).length }).length

How to add a textField to a specific row inside a table onclick of a button using reactjs & material ui

I want to add multiple textfield on to a specific row inside a table whenever the specific row add button is clicked, currently I am able to add text field onclick of add button but whenever the add button is clicked the textfield is getting added in every row of the table. Also the add icon needs to be next to the last text field but currently I could only achieve it having it on the 1st text field. Please someone help me out here. Image of what i have achieved so far.
As you can see I'm trying to add textfields on 1st row ,but it is automatically adding textfields in every row of table.
Working codesandbox:
https://codesandbox.io/s/broken-dream-7nncc?file=/src/App.js
There are a few ways to do it. A quick way is to (as Muhammad said) handle the button click for each row.
Meaning that you need to pass to the addCustomFile method the row Id and store this in your array.
Then when you map the customRow array in your main TableBody make sure to add the two custom columns only if there is a match between the customRow.rowID and the row ID you are currently rendering.
I`ve modified your sandbox https://codesandbox.io/s/infallible-resonance-qn64l?file=/src/App.js:1807-1820
you have to handle button click for each row. right now just one state so therefore it is showing in each cell
Maybe give this a try
https://www.w3schools.com/code/tryit.asp?filename=GQP3C100TJZH
hopefully it solves what you are looking for, if not please provide me with a bit more detailed issue of what exactly you want
This at the moment just works for one row and maybe for two rows you can try it by adding a it is not exactly a text field area but it should be a similar fix.

One form by row (fields for every column) with buttons for each: how to manage the dirty state?

I would like to handle the dirty state for every single row I have in my table. Unfortunately, adding a form around a would break the table, and I can't create it inside since I have a field for every different column. My last column for each row contains buttons: Delete and Update. Update appears only if one of the field of this row has been made dirty.
Somehow, it works already but I am checking each .pristine for every field on that row (#name="ngModel"). My rows are created through something like *ngFor="let row of rows". I believe it would be better to check the .dirty or .pristine on a form rather than on every single element.
Also, if I actually to the update, there is no way I can remove that .dirty status (I tried replacing the data for that row by removing from the array and re-adding it but it is still dirty).
Is there a technique to go around that?
You could use ngModelGroup around each of your rows. Then you can check the dirty flag for the group.

How to retrieve Material-UI <TableRow/>'s information based on selection on ReactJS?

I have a Material-UI's <Table/> (http://www.material-ui.com/#/components/table) with <TableRow/> with checkboxes set up on a ReactJS project. I am able to select the row by checking off the boxes, but how can I actually get it to log the information selected for that particular row?
I tried but only able to print how to ID of the row selected, rather than the information on that row.
http://www.webpackbin.com/4Jsi-1cn-
Thank you
Look at this:
http://www.webpackbin.com/Ey6da192b
Selected rows are getting by key from array in a state.

adding rows inside grid extjs

I am trying to add rows dynamically inside a grid using a button and remove individual rows using an action column function. I have two text fields (name, email) inside the grid on each row. So when the user hits the add button, a new row should appear with name and email fields. The third column would be an action column and when the button in the action column is clicked the entire row should be removed.
It would greatly help me out if somebody could share some sample code for me to get started.
There are some great code examples in the docs. This is where you have to head first, before asking here.
Look at this row editing example.

Categories