Discussion:
Sorting capabilities in Grid
(too old to reply)
Pier Alberto GUIDOTTI
2004-02-13 21:07:12 UTC
Permalink
Maybe this has already posted by many people: it would be a great thing if
records in grid could be ordered simply by clicking on the header of a
column.

Pier Alberto GUIDOTTI
Ken Mayer [dBASE, Inc.]
2004-02-13 21:39:56 UTC
Permalink
Post by Pier Alberto GUIDOTTI
Maybe this has already posted by many people: it would be a great thing if
records in grid could be ordered simply by clicking on the header of a
column.
It can. Try the onLeftMouseDown, or onLeftMouseUp events ... you have
to assign the code. The problem is ... what if there's no index for
that column? <g> If you want that functionality, you have to code it,
but the option is there.

Ken
---
Ken Mayer [dBASE, Inc.]
** Please respond ONLY in the newsgroups **

"Think OOP"

dBASE, Inc. website: http://www.dbase.com
Glenn Fausel
2004-02-13 21:42:09 UTC
Permalink
Post by Pier Alberto GUIDOTTI
Maybe this has already posted by many people: it would be a great thing if
records in grid could be ordered simply by clicking on the header of a
column.
Pier Alberto GUIDOTTI
You can create this yourself. Use the grid column heading control and use
either left double click or left mouse down to re-arrange each column. It may
be possible to create a custom grid to do this, but I don't have the time to
check that right now.

Glenn Fausel
Ken Mayer [dBASE, Inc.]
2004-02-13 22:41:45 UTC
Permalink
Post by Pier Alberto GUIDOTTI
Maybe this has already posted by many people: it would be a great thing if
records in grid could be ordered simply by clicking on the header of a
column.
Here's a weekend present, something I threw together in about half an
hour, and it could probably use some work. See the instructions in the
code (and watch for line wrapping and such):

/*
GridColumnIndexChange.cc
Programmer ...: Ken Mayer
Date..........: February 13, 2004
Notes.........: A custom grid that can be used to allow the
user to click on a columnHeading and
change the sort sequence of a rowset.
Note that this is not perfect, it only
works with grids that are datalinked
to a single rowset, and there are probably
some other issues that might cause problems.
Cobbled together based on a request in the
dBASE Wishlist newsgroup by Pier Alberto
Guidotti.

Usage Notes...: Make sure this is available as a custom
component:
set procedure to GridColumnIndexChange.cc
additive
Drag to a form.
Set the datalink.
Set the columns array (it won't work without it,
and currently we're not testing for that).
Run the form ...

Option........: grid.warnMessage -- this property will
cause a message to display on screen
for the user if the column heading selected
is for a column that doesn't have an index tag
by the fieldname ...
*/
class GridColumnIndexChange( oParent ) of grid( oParent ) custom

this.onOpen = class::SetColumnHeadings
this.WarnMessage = false

function SetColumnHeadings
// this should fire in the grid's onOpen, and set the
// column headings' onLeftMouseUp to fire the code
// 'ChangeIndex':
private aColumns
// use this so we know how many columns we have:
aColumns = this.getColumnOrder() // returns an array
for i = 1 to aColumns.size/2 // two columns in array
cColName = "column"+i
this.columns[ cColName ].headingControl.onLeftMouseUp =
class::ChangeIndex
next
return

function ChangeIndex(flags, col, row)
// This is a test, it is only a test
// for this to work for a 'custom grid', in the grid's
// onOpen we would need to loop through the
// columns, and set the headingControl's onLeftMouseUp
// event to this code ...
private nColumn, aColumns, cField, oRowSet, cOldIndex
nColumn = this.parent.currentColumn // get current column
aColumns = this.parent.getColumnOrder() // returns an array
cField = aColumns[ nColumn, 2 ] // fieldName
// Now we have the fieldname, try to set the
// index ... we're going to try just based on the
// fieldName ... there's no good way (without using
// a tableDef object) to find out if there's
// an index tag by a different name that will
// do the trick.
oRowSet = this.parent.dataLink
// in case it didn't work:
cOldIndex = oRowset.indexName
try
oRowset.indexName := cField
catch( Exception E )
if e.code # 239 // "Index does not exist"
msgbox( "Unexpected error: "+e.code+" -
"+e.message,"Error!", 16 )
else
// optional message:
if this.parent.warnMessage
msgbox( "No index is set for this field ...",
"Warning", 48 )
endif
endif
// error, set index to what it was before ...
oRowset.indexName := cOldIndex
endtry
return

endclass
---
Ken Mayer [dBASE, Inc.]
** Please respond ONLY in the newsgroups **

"Think OOP"

dBASE, Inc. website: http://www.dbase.com
Pier Alberto GUIDOTTI
2004-02-14 12:29:34 UTC
Permalink
Thanks Ken!

I'll try this very soon.
This could be very useful right now.

Pier Alberto GUIDOTTI
Post by Ken Mayer [dBASE, Inc.]
Here's a weekend present, something I threw together in about half an
hour, and it could probably use some work. See the instructions in the
Ken Mayer [dBASE, Inc.]
2004-02-14 14:04:42 UTC
Permalink
Post by Pier Alberto GUIDOTTI
Thanks Ken!
I'll try this very soon.
This could be very useful right now.
There will be a more robust version in the next release of the dUFLP.
<g> I added color to it last night ...

Ken
---
Ken Mayer [dBASE, Inc.]
** Please respond ONLY in the newsgroups **

"Think OOP"

dBASE, Inc. website: http://www.dbase.com
Pier Alberto GUIDOTTI
2004-02-16 07:43:36 UTC
Permalink
Ok, I will check next dUFLP release.

Thanks once again.

Pier Alberto GUIDOTTI
Post by Ken Mayer [dBASE, Inc.]
Post by Pier Alberto GUIDOTTI
Thanks Ken!
I'll try this very soon.
This could be very useful right now.
There will be a more robust version in the next release of the dUFLP.
<g> I added color to it last night ...
Ken
---
Ken Mayer [dBASE, Inc.]
** Please respond ONLY in the newsgroups **
"Think OOP"
dBASE, Inc. website: http://www.dbase.com
Ken Mayer [dBASE, Inc.]
2004-02-16 23:40:26 UTC
Permalink
Post by Pier Alberto GUIDOTTI
Ok, I will check next dUFLP release.
I've put a working version of this in the dbase.codelib newsgroup, it
seems to work pretty well, and it's documented, etc.

Have fun with it.

Ken
---
Ken Mayer [dBASE, Inc.]
** Please respond ONLY in the newsgroups **

"Think OOP"

dBASE, Inc. website: http://www.dbase.com

Loading...