Page 1 of 1

Datagrid sorting issues

Posted: Tue Jan 26, 2010 1:41 pm
by ukimiku
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,

Re: Datagrid sorting issues

Posted: Tue Jan 26, 2010 4:46 pm
by trevordevore
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?

Re: Datagrid sorting issues

Posted: Tue Jan 26, 2010 5:47 pm
by ukimiku
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,

Re: Datagrid sorting issues

Posted: Tue Jan 26, 2010 6:07 pm
by ukimiku
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,

Re: Datagrid sorting issues

Posted: Tue Jan 26, 2010 10:02 pm
by ecflyer
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

Re: Datagrid sorting issues

Posted: Tue Jan 26, 2010 10:29 pm
by Zryip TheSlug
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/

Re: Datagrid sorting issues

Posted: Tue Jan 26, 2010 10:59 pm
by ukimiku
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,

Re: Datagrid sorting issues

Posted: Wed Jan 27, 2010 3:44 pm
by trevordevore
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).

Re: Datagrid sorting issues

Posted: Wed Jan 27, 2010 5:03 pm
by ecflyer
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

Re: Datagrid sorting issues

Posted: Wed Jan 27, 2010 5:07 pm
by trevordevore
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.

Re: Datagrid sorting issues

Posted: Wed Jan 27, 2010 6:05 pm
by ukimiku
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,

Re: Datagrid sorting issues

Posted: Wed Jan 27, 2010 6:15 pm
by trevordevore
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

Re: Datagrid sorting issues

Posted: Wed Jan 27, 2010 7:49 pm
by ecflyer
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