1. Antony Xavier
  2. PowerBuilder
  3. Sunday, 19 November 2017 08:40 AM UTC

Good Day,

How to Get Actual Row number of a DataWindow in the initial retrieval, after applying the filter or sort is changed of a DataWindow using computed field?

Regards

Antony

Accepted Answer
Ricardo Colarina Accepted Answer Pending Moderation
  1. Sunday, 19 November 2017 23:06 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Antony,

Not sure exactly what you're trying to do, but does it have to be a computed field?  Would GetRowIDFromRow/GetRowFromRowID help?

Cheers.

Best Regards,

Ricardo

 

 

Comment
  1. Antony Xavier
  2. Monday, 20 November 2017 07:27 AM UTC
Hi Ricardo,



What I am looking how I can keep the orginal row number after retrieval of datawindow, if datawindow is filter, sort or delete records, without creating physical column or dummy column in the sql



​Regards



Antony



 



 

  1. Helpful
  1. Ricardo Colarina
  2. Thursday, 23 November 2017 23:15 PM UTC
Hi Antony,



So have you tried GetRowIDFromRow/GetRowFromRowID?  GetRowIDFromRow should give you the unique row identifier after retrieve.  GetRowIDFromRow will return the original id regardless of which buffer you access.



Cheers.



Best Regards,



Ricardo



 

  1. Helpful
  1. Antony Xavier
  2. Monday, 27 November 2017 09:54 AM UTC
It worked, Thank you very much

  1. Helpful
There are no comments made yet.
Lars Mosegaard Accepted Answer Pending Moderation
  1. Tuesday, 21 November 2017 05:37 AM UTC
  2. PowerBuilder
  3. # 1

In a computed field you can use GetRow() or CurrentRow().

GetRow() is the actual row number at the time.  Most useful in the detail band.

CurrentRow() on the other hand is same dw_1.GetRow() in powerscript script.

 

Comment
  1. Antony Xavier
  2. Tuesday, 21 November 2017 07:12 AM UTC
What about if apply filter / sort /delete operation in datawindow, we will loose original rownumber, so how we can keep orgincal rownumber atleast in the primary buffer?

  1. Helpful
  1. Lars Mosegaard
  2. Wednesday, 22 November 2017 03:33 AM UTC
I understand.



What you would normally need to do is; get the primary key value from the row before sort or filter, then find the row with that key and scroll to it.  If the row is in the filter buffer, do a RowsMove.



Something like this:



long ll_id, ll_row



ll_id = dw_x.GetItemNumber ( GetRow() , 'mykey' )



dw_x.SetFilter('amount>250')



dw_x.Filter()



dw_x.Sort ()



ll_row = dw_x.Find ( 'mykey=' + string ( ll_id ) , 1 , dw_x.RowCount() , Primary! )



if ll_row > 0 then



   dw_x.ScrollToRow ( ll_row )



else



   ll_row = dw_x.Find ( 'mykey=' + string ( ll_id ) , 1 , dw_x.RowCount() , Filter! )



  if ll_row > 0 then 



       dw_x.RowsMove ( ll_row,ll_row, Filter! , dw_x, 1 , Primary! )



       dw_x.Sort ()



          ll_row = dw_x.Find ( 'mykey=' + string ( ll_id ) , 1 , dw_x.RowCount() , Primary! )



         if ll_row > 0 then



          dw_x.ScrollToRow ( ll_row )



         end if



     end if 

  1. Helpful
  1. Antony Xavier
  2. Thursday, 23 November 2017 08:21 AM UTC
Thank you very much for your advice



It will work if a datawindow have a primary key (currently my code working in this secnario), but if it is dynamic and does not have a primary key will not work!!! any idea?



I tried by creating a computed column , but no hope eg."create compute(band=detail name=actual_rowid expression="if(actual_rowid>0,actual_rowid,getrow())"



thanks in advance

  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Sunday, 19 November 2017 17:23 PM UTC
  2. PowerBuilder
  3. # 2

The datawindow automatically renumbers all rows of data after a SORT, FIND, INSERT, or DELETE.
That's why row-based delete operations should always occur in reverse row order.

FOR ll_row = ll_rowcount TO 1 STEP -1

.....

NEXT

 

Later -

Oaln

 

 

Comment
There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Sunday, 19 November 2017 16:41 PM UTC
  2. PowerBuilder
  3. # 3

What do you mean actual row number? Row number should be independent of the data in the datawindow or datastore.

If you have code that's row number dependent, you should really consider changing to code to do a Find base on a key field(s), or some other unique piece of data.

If you can't do this for some reason, you could create a dummy column in your select, and immediately after the initial retrieve, fill it in with row number like this:

add "cast(0 as integer) as fake_row" to you select statement (note: your db may need different style of cast statment)

dw_1.retrieve()
long ctr
for ctr = 1 to dw_1.rowcount()
  dw_1.setitem(ctr, "fake_row", ctr)
next

No matter how you change sort order, or filters, the "fake_row" column will always contain the original row number (unless you do something that requires a reselectrow, in which case you'll need to save off the original value and restore it afterwards).

 

 

Comment
  1. Antony Xavier
  2. Monday, 20 November 2017 07:30 AM UTC
Hi Brad,



I am trying to solve inside the datawindow itself, eg. by creating dynamic computed column.



Regards

  1. Helpful
  1. Lars Mosegaard
  2. Wednesday, 22 November 2017 04:53 AM UTC
A computed field is just that.  It is computed all the time. Using Brads solution if you want the row number to not be computed after initial retrieve.

  1. Helpful
  1. Brad Mettee
  2. Wednesday, 22 November 2017 14:26 PM UTC
Antony,



We need the specifics of what you're trying to do. I can't think of any reason you would need to know the original row number for a computed field, and I don't think anyone else has got it yet either.

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.