Page 1 of 1
Is there a sample of how to update a collection from a multiple row grid?
Posted: Thu Nov 06, 2014 5:30 pm
by Andrew6784445
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?
Is there a sample of how to update a collection from a multiple row grid?
Posted: Thu Nov 06, 2014 7:23 pm
by Maryna Brodina
Is there a sample of how to update a collection from a multiple row grid?
Posted: Thu Nov 06, 2014 8:04 pm
by Andrew6784445
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:
Determine # rows in grid.
Cycle through each row and get values.
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
Is there a sample of how to update a collection from a multiple row grid?
Posted: Fri Nov 07, 2014 4:41 am
by Yurii Orishchuk
Hi Andrew,
Yes, your general plan is correct.
But please use following JS code in 3rd step instead of yours:
pre
console.log("Update '" + rowid + "' row");
rstEntityPerson_UpdatePhones.execute({body: { _id: rowid, "PhoneType":"Home" }
});
/pre
Regards.
Is there a sample of how to update a collection from a multiple row grid?
Posted: Fri Nov 07, 2014 5:55 am
by Andrew6784445
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.
Is there a sample of how to update a collection from a multiple row grid?
Posted: Sat Nov 08, 2014 1:50 pm
by Andrew6784445
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?
Is there a sample of how to update a collection from a multiple row grid?
Posted: Sat Nov 08, 2014 9:23 pm
by Andrew6784445
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?
Is there a sample of how to update a collection from a multiple row grid?
Posted: Mon Nov 10, 2014 4:59 am
by Yurii Orishchuk
Hi Andrew,
See following code:
pre
//This code only return you first component.
var grd = Appery("grdPhones");
//To get all components you should use following code:
var grd = jQuery('["grdPhones"]');
/pre
Regards.
Is there a sample of how to update a collection from a multiple row grid?
Posted: Mon Nov 10, 2014 3:06 pm
by Andrew6784445
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.
Is there a sample of how to update a collection from a multiple row grid?
Posted: Tue Nov 11, 2014 3:21 am
by Yurii Orishchuk
HI Andrew,
Yew, you are right.
Sorry for this typo.
Regards.