PDA

View Full Version : Spry - Javascript help!!! please :)




TheCoupe
Apr 4, 2011, 08:46 AM
Hi all,

can someone please point me in the right direction before I end up with no hair!!!

I have:
1 spry region on the left of my page
1 detail region on the right of my page
1 form to add further items to the detail region.

When I click on a row in the spry region, the detail region is displayed.
When I insert a new item to the detail region, I have the dataset reload, and therefore takes me back to display the first record in the detail region.

I am trying to have things so that when I've clicked on a row, that I can insert multiple items, one after the other, without having to click on the row each time to get back into that information.

What I've done so far is:
on Spry Region set an onclick="storeLastRow();"

Then I have:
var lastClickedRow=0;
function storeLastRow(){
lastClickedRow=staff.getRowNumber(staff.getCurrentRow());
alert("number is: " + lastClickedRow);
}
function PPEinsert(){
spryPopupDialog3.displayPopupDialog(false);
staff.addObserver({ onDataChanged: function(ds, type) {staff.setCurrentRowNumber(lastClickedRow); }});
alert("Current row is: " + lastClickedRow);
}

What I have works, but only after clicking the row twice. The first time I click a row, it displays the row number 0 in the alert, then if I click on a different row, it displays the row number relating to the first row I clicked.

Has anyone any idea how I can get the row number as soon as I click a row???

Any help would be greatly appreciated as this is doing my nutt!!!

Thanks



TheCoupe
Apr 6, 2011, 07:45 AM
Hi, for anyone attempting to do this in the future, I thought I would share how to do it.....

first off, you need to declare a variable, in my case, lastClickedRow, and have 2 functions, in my case, storeLastRow and setRowAfterUpdate.

var lastClickedRow=0;
function storeLastRow(){
lastClickedRow=ds.getRowNumber(ds.getCurrentRow());
}
function setRowAfterUpdate(){
ds.addObserver({ onDataChanged: function(ds, type) {ds.setCurrentRowNumber(lastClickedRow); }});

then from your table, you need to add 2 onclick events, the first is to take that current row id and set it, the second is to run one of the functions.

<tr spry:repeat="ds" spry:setrow="ds" onclick="ds.setCurrentRow('{ds_RowID}'); storeLastRow();">

then on submission of a form within the page... I am using the Spry PopUp and Spry Utilities from Linecraft Studio... you need to call the function setRowAfterUpdate, which will apply a filter to the dataset and leave you viewing the existing record after the dataset has been reloaded.