Le 23 avr. 10 à 13:25, Marcello Bertoli a écrit :

Hi Andre,

thanks again for your kind interest in solving this tricky issue.

I tried your code but the result is the same. It automates the process of clicking on two column headers.

What I would like to accomplish is different. I would like to sort with more than one criteria my datagrid rows when I click the header of the column date. Here there is an example of the scenario I would like to accomplish (look at the first two rows in both examples:

Number           Date                Customer
1               01/01/2010          aaaaaa
2               01/01/2010          bbbbbb
3               01/01/2010          cccccccc
4               02/01/2010          aaaaaaa
5               02/01/2010          bbbbbbb

I would like that when I sort by date, the data can also by sorted by (for example) customer (On the same date, the data must sorted alfabetically by Customer)

With your code (or with the default sorting code of datagrid) the result is this:

Number           Date                Customer
2              01/01/2010          bbbbbb
1               01/01/2010          aaaaaaa
3               01/01/2010          cccccccc
4               02/01/2010          aaaaaaa
5               02/01/2010          bbbbbbb

I can accomplish what I need querying the database with something like:

select number, date, customer from invoices order by date asc, customer asc

I think that, apart from the sql query, there are two chances:

1. The datagrid code can itself manage muti criteria sorting (maybe here Trevor can give us a hint) 2. We have to process the array of the datagrid, sorting with multicriteria and then populate again the datagrid with the new array.

Any idea?



Bonsoir Marcello,

Sorry again, I have been rather "slow"  to understand ;-))

I think that my first proposal was what you wanted except that I did it from a button (a mouseUp handler) while you wanted to it from a click on the header (which I proposed in my second solution, but then, I misunterpreted your sentence "I would like to sort the lines of the invoice datagrid first by invoice date and then by number"

Actually, to do a multi-criteria sorting (here two criteria) one must sort firstly by the second criteria, then by the first one. So that one gets the names in alphabetical order inside each date.

So a mixt of my two proposal seems to do the trick ( In fact it suffices to inverse the order of the two "dispatch" lines in the last script I send you (as they were in the first proposal); hence:
---------------------------------------
local hcColumn,theColumn
-------
on mouseDown
   ## just to be sure the sort types are right
set the dgColumnSortType["date"] of grp "datagrid 1" to "system dateTime"
   set the dgColumnSortType["name"] of grp "datagrid 1" to text

## to impose the sorting direction of "name"
set the dgColumnSortDirection["name"] of grp "datagrid 1" to "ascending"

## sorting by 2 criteria:alphabetical order of customers inside each date
   put the dgHeaderControl of the mouseControl into hcColumn
   if hcColumn is not empty then
      put the dgColumn of the target into theColumn
      if theColumn is "date" then
dispatch "sortByColumn" to the target with "name" ## second criterium
         --wait 1 sec
dispatch "sortByColumn" to the target with "date" ## first criterium
      end if
   end if
end mouseDown

Is this working as you are expecting (seems OK here in my trials)
(cross my fingers ;-o)))

Best regards from Grenoble

André



_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to