Page 1 of 1

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

Posted: Thu Apr 14, 2016 11:57 am
by Andy Parker

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.


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

Posted: Thu Apr 14, 2016 1:05 pm
by Serhii Kulibaba

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.


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

Posted: Thu Apr 14, 2016 4:19 pm
by Andy Parker

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?


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

Posted: Fri Apr 15, 2016 9:20 am
by Serhii Kulibaba

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?


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

Posted: Fri Apr 15, 2016 9:24 am
by Andy Parker

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.


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

Posted: Fri Apr 15, 2016 9:43 am
by Serhii Kulibaba

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