WebGrid Sorting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

WebGrid Sorting

Rob Rothwell
I got tired of my application failing if I tried to sort a WebGrid column with some nil elements, so I have created two methods:

WebGrid>>standardAscendingSortBlockForColumn: column
    ^[:a :b|
        | val1 val2 |
        val1:=a perform: column aspect.
        val2:=b perform: column aspect.
        val1 isNil
            ifTrue: [true]
            ifFalse: [val2 isNil
                ifTrue: [false]
                ifFalse: [val1 < val2]]]

and

standardDescendingSortBlockForColumn: column
    ^[:a :b|
        | val1 val2 |
        val1:=a perform: column aspect.
        val2:=b perform: column aspect.
        val1 isNil
            ifTrue: [false]
            ifFalse: [val2 isNil
                ifTrue: [true]
                ifFalse: [val1 > val2]]]


(There is probably a more compact way to do this if I was more experienced)

and have altered:

WebGrid>>sortColumnsIfNessesary
    | column sortBlock |
     self sortColumn isNil ifTrue: [^nil].
    column := self columns at: self sortColumn.
    sortBlock := (self sortOrder = #ascending)
        ifTrue: [ self standardAscendingSortBlockForColumn: column ]
        ifFalse: [ self standardDescendingSortBlockForColumn: column ].
    self collection: (SortedCollection withAll: self collection sortBlock: sortBlock).

Is this generally useful to Aida, or should it just be a WebGrid subclass like WebDataGrid?

I also have a WebGrid>>bindTo: method which will bind a WebGrid to an ODBCResultTable.  Would database components be generally useful to anyone else?  Probably not, unless you are planning on writing a DbVisualizer type of thing in Smalltalk (which I was thinking of doing as a more "business oriented" example).

This leads me to ask about future component naming conventions if people start contributing separately packaged Aida components.  Would you envision something like

Aida-Database
or
Aida-Database Components
or
Aida-Components-Database?

Just wondering.  It would be great if the Aida Squeaksource would become a repository for new components that could be plugged in to your application as needed!

Rob

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: WebGrid Sorting

Nicolas Petton
Rob,

Why do you have nil elements in your grid?

Nico

Le dimanche 06 avril 2008 à 15:25 -0400, Rob Rothwell a écrit :

> I got tired of my application failing if I tried to sort a WebGrid
> column with some nil elements, so I have created two methods:
>
> WebGrid>>standardAscendingSortBlockForColumn: column
>     ^[:a :b|
>         | val1 val2 |
>         val1:=a perform: column aspect.
>         val2:=b perform: column aspect.
>         val1 isNil
>             ifTrue: [true]
>             ifFalse: [val2 isNil
>                 ifTrue: [false]
>                 ifFalse: [val1 < val2]]]
>
> and
>
> standardDescendingSortBlockForColumn: column
>     ^[:a :b|
>         | val1 val2 |
>         val1:=a perform: column aspect.
>         val2:=b perform: column aspect.
>         val1 isNil
>             ifTrue: [false]
>             ifFalse: [val2 isNil
>                 ifTrue: [true]
>                 ifFalse: [val1 > val2]]]
>
>
> (There is probably a more compact way to do this if I was more
> experienced)
>
> and have altered:
>
> WebGrid>>sortColumnsIfNessesary
>     | column sortBlock |
>      self sortColumn isNil ifTrue: [^nil].
>     column := self columns at: self sortColumn.
>     sortBlock := (self sortOrder = #ascending)
>         ifTrue: [ self standardAscendingSortBlockForColumn: column ]
>         ifFalse: [ self standardDescendingSortBlockForColumn:
> column ].
>     self collection: (SortedCollection withAll: self collection
> sortBlock: sortBlock).
>
> Is this generally useful to Aida, or should it just be a WebGrid
> subclass like WebDataGrid?
>
> I also have a WebGrid>>bindTo: method which will bind a WebGrid to an
> ODBCResultTable.  Would database components be generally useful to
> anyone else?  Probably not, unless you are planning on writing a
> DbVisualizer type of thing in Smalltalk (which I was thinking of doing
> as a more "business oriented" example).
Can you explain a bit more please ?

Nico

>
> This leads me to ask about future component naming conventions if
> people start contributing separately packaged Aida components.  Would
> you envision something like
>
> Aida-Database
> or
> Aida-Database Components
> or
> Aida-Components-Database?
>
> Just wondering.  It would be great if the Aida Squeaksource would
> become a repository for new components that could be plugged in to
> your application as needed!
>
> Rob
> _______________________________________________
> Aida mailing list
> [hidden email]
> http://lists.aidaweb.si/mailman/listinfo/aida

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: WebGrid Sorting

Rob Rothwell
On Sun, Apr 6, 2008 at 6:02 PM, Nicolas Petton <[hidden email]> wrote:
Rob,

Why do you have nil elements in your grid?

Ahh...well, I am using WebGrid's primarily to display data from our hospital systems, which can frequently contain NULL values.  So, rather than mix my data types and display an empty string (which would really make sorting hard), we were happy to just see "nil" so we know that no data is available.

> I also have a WebGrid>>bindTo: method which will bind a WebGrid to an
> ODBCResultTable.  Would database components be generally useful to
> anyone else?  Probably not, unless you are planning on writing a
> DbVisualizer type of thing in Smalltalk (which I was thinking of doing
> as a more "business oriented" example).

Can you explain a bit more please ?

Sure...I thought it would be a fun example to create an application to connect to arbitrary data sources and explore their contents.  When you do that, you DEFINITELY get nil values in your grid as well!

Anyway, as a start, I just created a binding method to load the contents of a query into a WebGrid.  Ultimately, I think I would like a little more control over the grid (dragable columns, etc...) but that would require learning way more about JavaScript than I know right now!

Except for the features of the WebGrid, though, I think it would be pretty "easy" to create such an example with Aida...

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida