Hi,
I have an MVC site, and I have an igGrid on an edit page for managing the related entities of a given entity. For example, I have an Edit page for the Car entity, and on that page I have an igGrid for editing Passengers who belong to the given Car. Besides the "Car Edit" page, I also have a "New Car" page, which looks similar, but of course its Passengers grid is initially empty.
This work fine, but our customer wants a new feature: 'Cloning' of the Car entity, i.e. initializing a "New Car" page from an existing Car, which means setting the initial values of the "New Car" page to those of the original Car. (except the ID of course, which will be new) This includes related Passengers as well, so I'd like to initilalize a new igGrid from another (existing) entity's DataSource. I'd like to make and exact copy of the data present in the existing grid.
What I managed to do is to set the DataSourceUrl of the igGrid on the "New Car" Page to the Url of the existing Car's DataSource. So, the grid is correctly initialized with the existing Car's Passengers. However, when I save the page, nothing happens, I presume because igGird considers these rows as not modified, therefore they don't show up in igTransactions.
What I'd like to do is to make igGrid think these are 'new' rows, and when saving the grid, they would show up as "newrow" in igTransactions. I have seen that I can mark a row 'dirty', but this only makes it "updated', not "new", and I need them to be "new". I also see that I can add rows using Javascript, but it seems complicated at first (get the datasource, iterate through all rows, and insert them to the grid one by one.)
So, what is the recommended way to do what I described above? Is there a way to initialize an igGrid from an existing Datasource, or somehow mark all rows as "new", or, if none of these are possible, then, how should I load the contents of an existing DataSource to a new, empty igGrid using Javascript?
regards,
Peter
Hi Peter,
Thank you for posting in our forums!
I would recommend that, on server-side, the act of cloning be separate logic from just adding a new car with the grid's data.
Not knowing your whole scenario, there are some holes I am not sure of, so some of my advice may not be best for your whole scenario.
I would recommend that the server controls the logic of cloning as much as possible since it is focused more on the data than the UI, but I am not sure how responsive your app needs to be. If the user could wait for the server response to setup the server's cloned data, I would go with this route.
If you need a more client-focused UI, that will not be the best approach. You are right about the transactions not appearing as new rows when setting the datasource. When the grid is assigned a datasource, whatever data is not added by the user or programmatically is originally considered to be already in the datasource. Two solutions to this include:
1. As you mentioned, parsing the grid data and calling the addRow method programmatically.
2. You can extract the user's transactions with the allTransactions method, then create your own server call with the combined data you would need to update correctly on the server (cloned passengers that aren't exactly in the datasource + user data).
The first method is a little safer since the transactions will be entirely handled by the grid, but the second gives you a little more control.
Please let me know if this information helps or if you have any further questions or concerns with this.