Sorting datagrid column with a tricj?

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
Hi all,

given a datagrid (table) with three columns
C1 -> visible
C2 -> visible
C3 -> invisible column

Is it possible to sort a datagrid by column C3, although
the user has clicked the header of column C2.
Know what I mean?

If this is possible, any hints on how to do this are highly appreciated.


Best

Klaus

--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
Hi all,

> Am 02.11.2018 um 21:13 schrieb Klaus major-k via use-livecode <[hidden email]>:
>
> Hi all,
>
> given a datagrid (table) with three columns
> C1 -> visible
> C2 -> visible
> C3 -> invisible column
>
> Is it possible to sort a datagrid by column C3, although
> the user has clicked the header of column C2.
> Know what I mean?
>
> If this is possible, any hints on how to do this are highly appreciated.

I treid this one, which works, but the header of column "C2" does not change
to reflect the sort direction, it looks like inactive. Know what I mean?

So any clever hints or workaround still appreciated.


Best

Klaus
--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode


> Am 02.11.2018 um 21:27 schrieb Klaus major-k via use-livecode <[hidden email]>:
>
> Hi all,
>
>> Am 02.11.2018 um 21:13 schrieb Klaus major-k via use-livecode <[hidden email]>:
>>
>> Hi all,
>>
>> given a datagrid (table) with three columns
>> C1 -> visible
>> C2 -> visible
>> C3 -> invisible column
>>
>> Is it possible to sort a datagrid by column C3, although
>> the user has clicked the header of column C2.
>> Know what I mean?
>>
>> If this is possible, any hints on how to do this are highly appreciated.
>
> I tried this one, which works, but the header of column "C2" does not change
> to reflect the sort direction, it looks like inactive. Know what I mean?

Of course posting the script will help. 8-)
----------------------------------------------
on SortDataGridColumn pColumn
  if pColumn = "C2" then
    dispatch "SortByColumn" to me with "C3"
  else
    pass SortDataGridColumn
  end if
end SortDataGridColumn
--------------------------------------------


--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
In reply to this post by Geoff Canyon via use-livecode
There is no way I know of to have a datagrid sort by an invisible column and still show that it is sorted by a visible one. Every time the datagrid "redraws" it's going to update the appearance of the header to reflect the sort.

If you want to force the sort when you populate the datagrid, then set the dgProp ["sort by column"] of the datagrid to the column you want, and then if the user sorts by a different column, well that's on them.

Bob S


> On Nov 2, 2018, at 13:13 , Klaus major-k via use-livecode <[hidden email]> wrote:
>
> Hi all,
>
> given a datagrid (table) with three columns
> C1 -> visible
> C2 -> visible
> C3 -> invisible column
>
> Is it possible to sort a datagrid by column C3, although
> the user has clicked the header of column C2.
> Know what I mean?
>
> If this is possible, any hints on how to do this are highly appreciated.
>
>
> Best
>
> Klaus
>
> --
> Klaus Major
> http://www.major-k.de
> [hidden email]
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
Hi Bob,

> Am 02.11.2018 um 22:14 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>
> There is no way I know of to have a datagrid sort by an invisible column and still show that it is sorted by a visible one. Every time the datagrid "redraws" it's going to update the appearance of the header to reflect the sort.

I was afraid of that.

> If you want to force the sort when you populate the datagrid, then set the dgProp ["sort by column"] of the datagrid to the column you want, and then if the user sorts by a different column, well that's on them.

We have a german app for Android and LC on Android still does not support "system date"! :-/
So I wanted to fake sorting a column with long german dates by sorting by a hidden column with an english date.
Will have to roll my own with list fields.

Thank you!

> Bob S

Best

Klaus


--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
In a table datagrid, can't you edit the column template so that you can control what goes into the field for that column? I think the underlying data will remain the same, but what goes into the field is what you put there. I suspect the datagrid will then sort by the underlying data, not the displayed data.

I have a similar issue with SQL formatted dates, but I want to display them as long dates. I'll toy around with this and see what I come up with.

Bob S


> On Nov 2, 2018, at 14:26 , Klaus major-k via use-livecode <[hidden email]> wrote:
>
> Hi Bob,
>
>> Am 02.11.2018 um 22:14 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>>
>> There is no way I know of to have a datagrid sort by an invisible column and still show that it is sorted by a visible one. Every time the datagrid "redraws" it's going to update the appearance of the header to reflect the sort.
>
> I was afraid of that.
>
>> If you want to force the sort when you populate the datagrid, then set the dgProp ["sort by column"] of the datagrid to the column you want, and then if the user sorts by a different column, well that's on them.
>
> We have a german app for Android and LC on Android still does not support "system date"! :-/
> So I wanted to fake sorting a column with long german dates by sorting by a hidden column with an english date.
> Will have to roll my own with list fields.
>
> Thank you!
>
>> Bob S
>
> Best
>
> Klaus
>
>
> --
> Klaus Major
> http://www.major-k.de
> [hidden email]
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
Okay, looks like this is a no go. I read from one of the datagrid lessons in reference to populating the datagrid "by hand":

Important: When using this technique properties like dgData, dgText, dgDataOfIndex, etc. will no longer return values. The data grid is just displaying records from your data source. It does not store any of that data internally.

What I would like to see added to the datagrid is a handler that intercepted the population of a field so what goes into the field can be custom formatted. This comes up a lot. Dates and numbers from an SQL query are unformatted, and having to go through the datagrid when populating and formatting each record's data before displaying it, and then reformatting it before pushing it back up to the database seems like more work than necessary.

Bob S


> On Nov 2, 2018, at 14:42 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> In a table datagrid, can't you edit the column template so that you can control what goes into the field for that column? I think the underlying data will remain the same, but what goes into the field is what you put there. I suspect the datagrid will then sort by the underlying data, not the displayed data.
>
> I have a similar issue with SQL formatted dates, but I want to display them as long dates. I'll toy around with this and see what I come up with.
>
> Bob S
>
>
>> On Nov 2, 2018, at 14:26 , Klaus major-k via use-livecode <[hidden email]> wrote:
>>
>> Hi Bob,
>>
>>> Am 02.11.2018 um 22:14 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>>>
>>> There is no way I know of to have a datagrid sort by an invisible column and still show that it is sorted by a visible one. Every time the datagrid "redraws" it's going to update the appearance of the header to reflect the sort.
>>
>> I was afraid of that.
>>
>>> If you want to force the sort when you populate the datagrid, then set the dgProp ["sort by column"] of the datagrid to the column you want, and then if the user sorts by a different column, well that's on them.
>>
>> We have a german app for Android and LC on Android still does not support "system date"! :-/
>> So I wanted to fake sorting a column with long german dates by sorting by a hidden column with an english date.
>> Will have to roll my own with list fields.
>>
>> Thank you!
>>
>>> Bob S
>>
>> Best
>>
>> Klaus
>>
>>
>> --
>> Klaus Major
>> http://www.major-k.de
>> [hidden email]
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
On Fri, Nov 2, 2018 at 5:16 PM Bob Sneidar via use-livecode <
[hidden email]> wrote:

>
> What I would like to see added to the datagrid is a handler that
> intercepted the population of a field so what goes into the field can be
> custom formatted. This comes up a lot. Dates and numbers from an SQL query
> are unformatted, and having to go through the datagrid when populating and
> formatting each record's data before displaying it, and then reformatting
> it before pushing it back up to the database seems like more work than
> necessary.
>

The Data Grid already supports this. Just customize the default column
behavior. Take a look at this article which truncates text that is too wide:

http://lessons.livecode.com/m/datagrid/l/7327-how-do-i-override-the-default-behavior-for-rendering-data-to-a-cell

--
Trevor DeVore
ScreenSteps
www.screensteps.com
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
In reply to this post by Geoff Canyon via use-livecode
Hi Bob,

> Am 02.11.2018 um 22:42 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>
> In a table datagrid, can't you edit the column template so that you can control what goes into the field for that column? I think the underlying data will remain the same, but what goes into the field is what you put there. I suspect the datagrid will then sort by the underlying data, not the displayed data.
>
> I have a similar issue with SQL formatted dates, but I want to display them as long dates. I'll toy around with this and see what I come up with.
>
> Bob S

thank you, I think I found a woraround for me.


Best

Klaus
--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
In reply to this post by Geoff Canyon via use-livecode
Thanks Trevor. I perused the lessons and the documentation but could not find anything that might aid me in this. I will have a look at that lesson!

Bob S


> On Nov 2, 2018, at 15:49 , Trevor DeVore via use-livecode <[hidden email]> wrote:
>
> On Fri, Nov 2, 2018 at 5:16 PM Bob Sneidar via use-livecode <
> [hidden email]> wrote:
>
>>
>> What I would like to see added to the datagrid is a handler that
>> intercepted the population of a field so what goes into the field can be
>> custom formatted. This comes up a lot. Dates and numbers from an SQL query
>> are unformatted, and having to go through the datagrid when populating and
>> formatting each record's data before displaying it, and then reformatting
>> it before pushing it back up to the database seems like more work than
>> necessary.
>>
>
> The Data Grid already supports this. Just customize the default column
> behavior. Take a look at this article which truncates text that is too wide:
>
> http://lessons.livecode.com/m/datagrid/l/7327-how-do-i-override-the-default-behavior-for-rendering-data-to-a-cell
>
> --
> Trevor DeVore
> ScreenSteps
> www.screensteps.com
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
Hi Trevor.

Just a heads up, I followed those instructions in the lesson to the letter. It broke my datagrid. It would no longer populate and I could not select a row by clicking on it.

It may have to do with the new dg behavior heirarchy. I could see that someone else was having difficulty as late as last Friday, although it looks like it's a different issue.

I'll poke around with it and see if I can figure out why, but it looks to me that the new behavior object is not getting any messages sent to it.

Bob S


> On Nov 4, 2018, at 19:44 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> Thanks Trevor. I perused the lessons and the documentation but could not find anything that might aid me in this. I will have a look at that lesson!
>
> Bob S
>
>
>> On Nov 2, 2018, at 15:49 , Trevor DeVore via use-livecode <[hidden email]> wrote:
>>
>> On Fri, Nov 2, 2018 at 5:16 PM Bob Sneidar via use-livecode <
>> [hidden email]> wrote:
>>
>>>
>>> What I would like to see added to the datagrid is a handler that
>>> intercepted the population of a field so what goes into the field can be
>>> custom formatted. This comes up a lot. Dates and numbers from an SQL query
>>> are unformatted, and having to go through the datagrid when populating and
>>> formatting each record's data before displaying it, and then reformatting
>>> it before pushing it back up to the database seems like more work than
>>> necessary.
>>>
>>
>> The Data Grid already supports this. Just customize the default column
>> behavior. Take a look at this article which truncates text that is too wide:
>>
>> http://lessons.livecode.com/m/datagrid/l/7327-how-do-i-override-the-default-behavior-for-rendering-data-to-a-cell
>>
>> --
>> Trevor DeVore
>> ScreenSteps
>> www.screensteps.com
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
In reply to this post by Geoff Canyon via use-livecode
I think at some point the way this needs to work is to send fillInData message to the script of the datagrid. Most LC devs see the datagrid as a complex magical black box kind of object, and are reticent to pull it apart or copy bits of it to other places to get it to do something different.

If fillInData were sent to the datagrid after it was done doing it's thing, it would be much cleaner. I'm going to try to edit the default column behavior to do just that, and if I can get it to work, I'll submit a change request.

Bob S


> On Nov 4, 2018, at 19:44 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> Thanks Trevor. I perused the lessons and the documentation but could not find anything that might aid me in this. I will have a look at that lesson!
>
> Bob S
>
>
>> On Nov 2, 2018, at 15:49 , Trevor DeVore via use-livecode <[hidden email]> wrote:
>>
>> On Fri, Nov 2, 2018 at 5:16 PM Bob Sneidar via use-livecode <
>> [hidden email]> wrote:
>>
>>>
>>> What I would like to see added to the datagrid is a handler that
>>> intercepted the population of a field so what goes into the field can be
>>> custom formatted. This comes up a lot. Dates and numbers from an SQL query
>>> are unformatted, and having to go through the datagrid when populating and
>>> formatting each record's data before displaying it, and then reformatting
>>> it before pushing it back up to the database seems like more work than
>>> necessary.
>>>
>>
>> The Data Grid already supports this. Just customize the default column
>> behavior. Take a look at this article which truncates text that is too wide:
>>
>> http://lessons.livecode.com/m/datagrid/l/7327-how-do-i-override-the-default-behavior-for-rendering-data-to-a-cell
>>
>> --
>> Trevor DeVore
>> ScreenSteps
>> www.screensteps.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
In reply to this post by Geoff Canyon via use-livecode
On Mon, Nov 5, 2018 at 11:03 AM Bob Sneidar via use-livecode <
[hidden email]> wrote:

> Hi Trevor.
>
> Just a heads up, I followed those instructions in the lesson to the
> letter. It broke my datagrid. It would no longer populate and I could not
> select a row by clicking on it.
>
> It may have to do with the new dg behavior heirarchy. I could see that
> someone else was having difficulty as late as last Friday, although it
> looks like it's a different issue.


I would suggest submitting a note on the article letting the team know. You
are probably right about the new dg behavior changes breaking it. I know it
used to work as that is how I always customized how columns display data
when it was simply a matter of reformatting the text.

--
Trevor DeVore
ScreenSteps
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Sorting datagrid column with a tricj?

Geoff Canyon via use-livecode
Hi Trevor.

Actually I came up with a fairly elegant solution which is quite simple. In the column behavior script I added some code:

on FillInData pData
   -- This message is sent when the Data Grid needs to populate
   -- this template with the column data. pData is the value to be displayed.
   set the text of the long ID of me to pData ## temp workaround for
   
   -- Sly Labs! Custom Column Formatting
   dispatch customFillInData to me with pData, the dgColumn of me
end FillInData

Of course, I had to edit the permissions of the folder containing the behavior script, as well as the script only stack itself so I could save the changes.

Next I added this to my datagrid:

on customFillInData pData, pColumn
   switch pColumn
      case "lastupdate"
         put the text of the target into tColumnValue
         if tColumnValue is not empty then \
               set the text of the target to \
               formatDate(word 1 of tColumnValue, "abbr date") && word 2 of tColumnValue
               -- formatDate() is my own function which converts any date to one of several custom formats LC does not use
         break
   end switch
end customFillInData
   
Not only does this work famously, but it does not affect the underlying data. It only updates the value in the datagrid field. This can be built upon to create datagrids which have a spreadsheet-like field formatting while the underlying data is the raw value. You could even store equasions and then resolve the equasions in the display, just like a spreadsheet.

I'll have to figure out how to reformat going the other direction, so that editing the displayed data will store the raw value and not the displayed value.

Anyone wanna chime in on this method before I submit a change request?

Bob S


> On Nov 5, 2018, at 09:22 , Trevor DeVore via use-livecode <[hidden email]> wrote:
>
> On Mon, Nov 5, 2018 at 11:03 AM Bob Sneidar via use-livecode <
> [hidden email]> wrote:
>
>> Hi Trevor.
>>
>> Just a heads up, I followed those instructions in the lesson to the
>> letter. It broke my datagrid. It would no longer populate and I could not
>> select a row by clicking on it.
>>
>> It may have to do with the new dg behavior heirarchy. I could see that
>> someone else was having difficulty as late as last Friday, although it
>> looks like it's a different issue.
>
>
> I would suggest submitting a note on the article letting the team know. You
> are probably right about the new dg behavior changes breaking it. I know it
> used to work as that is how I always customized how columns display data
> when it was simply a matter of reformatting the text.
>
> --
> Trevor DeVore
> ScreenSteps
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode