Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cloning the last row of a dynamic grid that is populated by a REST call

I have a label that sits within a grid that is populated automatically by an array from a DB via a rest call.

I need to figure out how to add a row to the end of this grid using javascript - as it is a comments grid.
I will then update the database with the new comment.

I've tried using the following code:
<code>
var commentgrid = $(commentgridc).find("[name='comment_grid']");
console.log("comments length:"+$(commentgrid).length);
var comments = $(commentgrid).find("[name='comments']");
console.log("commentgrid:"+$(comments).attr('name'));
//
// Now we have the comments grid name, lets duplicate the last row
//
var $tr = $(commentgrid).find('tr:last').clone();
$(commentgrid).append($tr);
</code>

this sort of works, but doesn't duplicate the last row, it seems to duplicate all rows a couple of times.

Can someone help me with this please? I simply want a new row created that has the same label so I can set the label contents.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Cloning the last row of a dynamic grid that is populated by a REST call

Hello Andy,

It is better to save full service response to the storage variable (https://devcenter.appery.io/documenta...), add the last row to that variable and use it in the mapping right after that.

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cloning the last row of a dynamic grid that is populated by a REST call

Thanks Sergiy,

I've added the storage to do this and I'm mapping to it, so all good there.

I've built a DIV that contains all the elements I need for each array item from the storage.

My question is, how do I clone that DIV (div is called duplicater_div) as I load in the data?

I've tried the following code:
code
var i = 0;
var original = Appery('duplicater_div');
&#47;&#47;
var clone = original&#46;cloneNode(true); &#47;&#47; "deep" clone
clone&#46;id = "duplicater" + ++i;
&#47;&#47; or clone&#46;id = "&quot if the divs don't need an ID
original&#46;parentNode&#46;appendChild(clone);

/code

I constantly get the error:
Uncaught TypeError: original.cloneNode is not a function

any suggestions?

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Cloning the last row of a dynamic grid that is populated by a REST call

Could you clarify, how did you create that div? Is it a html component with your custom layout or it was created with service's mapping?

Andy Parker
Posts: 0
Joined: Wed Mar 27, 2013 10:21 am

Cloning the last row of a dynamic grid that is populated by a REST call

Hi Sergiy,

I created the DIV using the Appery builder.

I want that as the template, and then I want to clone it for each record I have saved in the storage that was created from the REST call.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Cloning the last row of a dynamic grid that is populated by a REST call

We are very sorry, but this is something outside the scope (http://devcenter.appery.io/support-po...) of our standard support.

Please use for that method html, e.g.:
prevar i = 0;
var original = $(Apperyio('duplicater_div')&#46;html());
original&#46;attr("id", "duplicater" + ++i);
original&#46;parentNode&#46;appendChild(clone);/pre

Return to “Issues”