Datagrid sorting issues

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

Datagrid sorting issues

Post by ukimiku » Tue Jan 26, 2010 1:41 pm

Hi group,

whenever I load data into my datarid, the grid sorts by a certain column. I want to disable any kind of automatic sorting alltogether, but cannot find how to. When I check the "Columns" tab in the property inspector for the datagrid, the checkbox for the respective column ("Sort by column") is not ticked. But still, the data grid sorts my data every time I load data into it. When I set up the datagrid, no column was selected, and the datagrid did not perform any automatic sorting. Then I accidentally clicked on one of the column headers, and the automatic sorting took place once. Now whatever my settings and attemps at changing, I cannot get rid of the sorting again, and the column mentioned above stays highlighted.

How can I disable sorting?

Thanks,

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Datagrid sorting issues

Post by trevordevore » Tue Jan 26, 2010 4:46 pm

The lesson How Do I Customize Column Sorting? has some hints as to how to disable sorting. I just went ahead and created a new lesson that addresses this specifically though.

How Do I Disable Column Sorting?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

Re: Datagrid sorting issues

Post by ukimiku » Tue Jan 26, 2010 5:47 pm

Hi Trevor,

wow - that's what I call service! :) Before reading your explanations, I had done a forum search for related posts and also read through your datagrid API. In the forum, I had already found the command you provided, to be entered and executed in the message box,

Code: Select all

set the dgProp["sort by column"] of group "Grades" to empty
which, unfortunately, however, has had no effect whatsoever on my datagrid. I replaced the name of the datagrid with the correct designation (in my case, "Grades"), but to no avail. The header of the column in question remaines highlighted, in contrast to the before/after screenshots you provided in your web tutorial. Then I tried your command in the openStack handler as well, but that didn't work either, the column header remains highlighted, just as before. I then searched the whole stack for any places in which I might accidentally enable the sorting programatically, but there is no such place. I also implemented the empty onSortDataGrid handler as you suggested, no luck there.

Now I'm at a loss. The only thing I noticed is that the stubborn column in my data grid is very tight, only 30 pixels wide. Would that matter? And another deviation from your code examples is the fact that my column is named "Ø" (for average). Would that cause a problem?

[testing...]

No, that does not seem to be part of the problem. After a complete reload of the stack containing the datagrid, I can rename the column labels again (which was impossible just before), but the sorting remains, even after reissuing your command.

??

Regards,

ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

Re: Datagrid sorting issues

Post by ukimiku » Tue Jan 26, 2010 6:07 pm

Trevor,

another oddity: when I now tried to execute your set dGProp command again, the message box responded by saying
Message execution error:
Error description: Chunk: can't find object
I then created a new card (empty) for the same stack, deleted the new card again without doing anything with it, and then issued your command again, and now the message box error is gone, nothing is returned by the message box, but the column remains highlighted, and the sorting enabled.

?

Regards,

ecflyer
Posts: 24
Joined: Tue Oct 20, 2009 12:04 am

Re: Datagrid sorting issues

Post by ecflyer » Tue Jan 26, 2010 10:02 pm

I have a similar question on using the dgProp commands and trying to get the header alignment to be center. I have read through the manual and looked at the dgColumnAlignment in the API. I have tried to write a script to get this to work. Here's something I tried:

on preOpenCard
set the dgColumnAlignment ["date"] of grp "DataGrid" to center
end preOpenCard

I don't know if I should be using a preOpenStack handler or if I need to call out the dgProp to access it. I tired by adding:

put the dgProp[ dgColumnAlign ] of group "Data Grid" -- into the preOpenCard handler and into the message box.

Basically, I'm very know to programming and can not seem to figure out how to use the DataGrid properties with script (although I have been successful with other dg issues).
Sorry for the elementary questions. I do think the DG is a great tool. Thanks for it's creation and help to all as always.

Thanks,
Eric

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: Datagrid sorting issues

Post by Zryip TheSlug » Tue Jan 26, 2010 10:29 pm

I have a similar question on using the dgProp commands and trying to get the header alignment to be center. I have read through the manual and looked at the dgColumnAlignment in the API. I have tried to write a script to get this to work. Here's something I tried:
on preOpenCard
set the dgColumnAlignment ["date"] of grp "DataGrid" to center
end preOpenCard
Hi Eric,

Headers are specifics groups. To set the header alignment to center, you have to use the dgHeaderAlignment property like this :

on preOpenCard
set the dgHeaderAlignment ["date"] of grp "DataGrid" to "center"
end preOpenCard[/quote]

Plus don't forget to set the alignment value between two quotes.

HTH

--
Zryip TheSlug wish you the best! 8-)
http://www.aslugontheroad.co.cc/
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

Re: Datagrid sorting issues

Post by ukimiku » Tue Jan 26, 2010 10:59 pm

Hi Trevor,

an update on my problem:

I managed to replace the datagrid with the permanently highlighted column header with an old version that does not have any highlighted column headers and thus no automatic sorting. Anyway, when I give the set dgProp["sort by column"] command, nothing changes, i.e. I can still click on any column header and make the datagrid sort. This highlighting cannot be undone, and I am stuck with the same situation as before.

Regards,

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Datagrid sorting issues

Post by trevordevore » Wed Jan 27, 2010 3:44 pm

ukimiku - Setting the "sort by column" property doesn't disable sorting. Try adding the command to your Data Grid script as described in the lesson pointed you to and then column sorting will be disabled.

How Do I Disable Column Sorting?

Note: If you add the SortDataGridColumn handler to the Data Grid setting the dgProps["sort by column"] will not work anymore. If you wanted to set the "sort by column" property later on you would need to remove the SortDataGridColumn handler from the script (or at least pass the message).
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

ecflyer
Posts: 24
Joined: Tue Oct 20, 2009 12:04 am

Re: Datagrid sorting issues

Post by ecflyer » Wed Jan 27, 2010 5:03 pm

Thank you for the clarification on the dgHeaderAlign.

I got the headers to align center with

on preOpenCard
set the dgHeaderAlignment ["columnName"] of grp "DataGrid" to "center"
end preOpenCard

This only seems to work if I send the preOpenCard handler message while the stack is open, i.e. "send card message > "preOpenCard"". When I save, close, and then re-open the stack, the headers will not align center. I know there is probably something simply I am not getting; I hope that the answer will help me understand how to create additional messages from the user to the dg.

thanks again,
E

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Datagrid sorting issues

Post by trevordevore » Wed Jan 27, 2010 5:07 pm

You aren't missing anything but rather there is a bug in the current Data Grid library. This is fixed for the next release.

You can download a version of the library with a fix from http://bluemango.backpackit.com/pub/183 ... -data-grid. The page also has instructions for updating installing the updated library.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

ukimiku
Posts: 101
Joined: Thu Oct 22, 2009 10:45 am

Re: Datagrid sorting issues

Post by ukimiku » Wed Jan 27, 2010 6:05 pm

Hi Trevor,

thanks for your patience. I added the sortDataGridColumn handler. Before that, I issued the dgProp property set command. After several reloads of the stack, now the sorting is finally disabled.

Is there a way to learn what setting has precedence over which other settings? For example, you noted that the set dgProp command does not work anymore after adding the handler for sorting columns. Why? What kind of hierarchy is at work here?

I noted that when I opened the template group for my datagrid (table type), the openStack handler of my stack was automatically called, and then RunRev complained that it couldn't find anymore the datagrid referenced there. What does that mean?

Again, thanks. I had already considered placing transparent image stripes over the column headers to catch the devilish sorting mouse clicks! This is unnecessary now, thanks.

Regards,

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Location: Overland Park, Kansas
Contact:

Re: Datagrid sorting issues

Post by trevordevore » Wed Jan 27, 2010 6:15 pm

Is there a way to learn what setting has precedence over which other settings?
The lesson on customizing sorting explains the relationships between the SortDataGridColumn Message and the "sort by column" property.

http://lessons.runrev.com/spaces/lesson ... n-Sorting-
I noted that when I opened the template group for my datagrid (table type), the openStack handler of my stack was automatically called
The Data Grid templates are stored in a substack of your main stack. It appears that you have put your openStack handler in the stack script of your main stack. This means that any substacks that open will trigger your openStack handler. If you don't explicitly check that the owner of the target is your mainstack (openStack message is sent to card, not stack) then you will get unexpected behavior.

In your case I'm guessing you call some code that targets with the Data Grid. Since the Data Grid template stack is the frontmost stack the engine will look to it to resolve any object references. Since your Data Grid doesn't exist on the template stack you get an error.

So you need to either A) move your openStack handler to a card script so it won't be triggered when substacks open or B) and a check:

Code: Select all

on openStack
    if the owner of the target is not me then pass openStack

    ...
end openStack
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

ecflyer
Posts: 24
Joined: Tue Oct 20, 2009 12:04 am

Re: Datagrid sorting issues

Post by ecflyer » Wed Jan 27, 2010 7:49 pm

Thanks Trevor, that seemed to have fixed the problem. Not only that, now when I resize the column, the header stays in the center. It was not doing that before and I thought I would have to write a mouseMove handler as well. Thanks for being so accommodating to this novice.
E

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”