Andrew6784445
Posts: 1
Joined: Fri Apr 04, 2014 2:08 pm

Is there a sample of how to update a collection from a multiple row grid?

I have created a grid based on a db service query. I have tried to update the collection using info from:

https://getsatisfaction.com/apperyio/...

Is there a "Best Practice" example of how to pull data from a collection into a grid, then update the collection from the grid?

Andrew6784445
Posts: 1
Joined: Fri Apr 04, 2014 2:08 pm

Is there a sample of how to update a collection from a multiple row grid?

I don't see any examples in the tutorial where there is a grid involved and how to set up the response to read through the grid data and update each _id. Am I missing it somewhere in the tutorial...which section should I look at?

It seems that the solution is to use js to:

  1. Determine # rows in grid.

  2. Cycle through each row and get values.

  3. Execute response passing data.

    Unfortunately, I get a bad request "database id not specified" when I try the following code on click from my save button:

    var grd = Appery("grdPhones");

    //1. Determine # rows in grid.
    for(var i = 0; i < grd.length; i++){
    var row = jQuery(grd);

    //2. Cycle through each row and get values.
    var rowid = row.find("[name=lblEntityPhone_id]").text();
    alert(rowid);

    //3. Execute response passing data.
    rstEntityPerson_UpdatePhones.execute({ data: {"_id": rowid,"PhoneType":"Home"} });

    The alert displays the correct rowid and when checking the grid, it displays the correct number of rows.

    Thanks,

    Andrew

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Is there a sample of how to update a collection from a multiple row grid?

Hi Andrew,

Yes, your general plan is correct.

But please use following JS code in 3rd step instead of yours:

pre

console&#46;log("Update '" + rowid + "' row");
rstEntityPerson_UpdatePhones&#46;execute({body: { _id: rowid, "PhoneType":"Home" }
});

/pre

Regards.

Andrew6784445
Posts: 1
Joined: Fri Apr 04, 2014 2:08 pm

Is there a sample of how to update a collection from a multiple row grid?

Thanks Yurii,

I copied and pasted but still get the error: {"code":"DBSG002","description":"database id not specified"}

The console shows the correct row in my collection that needs to be updated.

Do I need to modify the service at all? I know that _id and PhoneType exist in the body.

BTW, your code does not have quotation marks around _id. I tried it with the quotation marks and it still didn't work. I'm confused whether or not it should be in quotation marks.

Image

Andrew6784445
Posts: 1
Joined: Fri Apr 04, 2014 2:08 pm

Is there a sample of how to update a collection from a multiple row grid?

I am now able to update using the body parameter with "_id":rowid.

Unfortunately, the grd.length is returning 1 even though the grid may contain multiple rows from the response that it is linked to. Is the grd.length linked to the "design time" rows?

How do I get the actual number of rows as created by the response? Do I have to count the rows on completion of the response? Is there a response property that I can read or how and where should I implement a count?

Andrew6784445
Posts: 1
Joined: Fri Apr 04, 2014 2:08 pm

Is there a sample of how to update a collection from a multiple row grid?

I set a local storage variable to keep track of the number of rows when fetching data using my query service. Is there a better way?

My counter correctly reports the right number of rows but when I try to iterate through the grid rows (row = jQuery(grd)) only the first iteration returns data...the rest are null.

I think I don't understand how the grid component works when rows are created by a query service. How do I access rows that are not present at design time?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Is there a sample of how to update a collection from a multiple row grid?

Hi Andrew,

See following code:

pre

&#47;&#47;This code only return you first component&#46;
var grd = Appery("grdPhones");

&#47;&#47;To get all components you should use following code:
var grd = jQuery('["grdPhones"]');

/pre

Regards.

Andrew6784445
Posts: 1
Joined: Fri Apr 04, 2014 2:08 pm

Is there a sample of how to update a collection from a multiple row grid?

Thank you Yurii.

I had to use:

var grd=jQuery('[name="grdPhones"]');

to get it to work but you pointed me in the right direction.

Thanks again.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Is there a sample of how to update a collection from a multiple row grid?

HI Andrew,

Yew, you are right.

Sorry for this typo.

Regards.

Return to “Issues”