Data Grid Form Sort Column

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
Xero
Posts: 36
Joined: Sat Jun 23, 2018 2:22 pm

Data Grid Form Sort Column

Post by Xero » Tue Aug 21, 2018 3:54 pm

Hey all,
I have set up a DataGrid with a "Form" type. (See picture)
It has a Row Template set up with a checkbox, Label and Field "Rating". I used the "Working with checkboxes" tutorial to set it up, then hacked another part to it.
I have set up code that works to add a number into the rating if it appears in a series of checkboxes on other cards. Essentially, tracking how popular each item is.
I want to sort the entries now so that the exercises with the most numbers in the "Rating" field appears at the top.
Essentially, I want to sort the column of the form by the field "Ranking".
Problem is... as a Form type, there doesn't seem to be a sort by column function...
The other option would be to change the DG to have columns, which would allow me to do it, but would prefer not to.
Thoughts?
XdM
Attachments
LC DG Form Sort.jpg
LC DG Form Sort.jpg (14.23 KiB) Viewed 321 times

mrcoollion
Posts: 343
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Data Grid Form Sort Column

Post by mrcoollion » Tue Aug 21, 2018 4:08 pm

This might be a solution.

http://lessons.livecode.com/m/datagrid/ ... y-s-values

Greetings,

Paul

Klaus
Posts: 10490
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid Form Sort Column

Post by Klaus » Tue Aug 21, 2018 4:09 pm

Hi Xero,

check "SortDataByKey" in the dictionary, that case also be used with datagrid FORMS!


Best

Klaus

Xero
Posts: 36
Joined: Sat Jun 23, 2018 2:22 pm

Re: Data Grid Form Sort Column

Post by Xero » Tue Aug 21, 2018 4:30 pm

Cool.
Legend... wait for it...
ary.
Right...
One issue now I have tested it...
I can't add to the Rating field...
This is the code I am using:

Code: Select all

  
      if the hilited of button "BPMNo" of card "OneVideo" then
      put "6,17,19,20,29,30" into tAList
      set the itemdelimiter to comma
      repeat for each item x in TAList
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "checked", true
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "Rating", +1
      end repeat
   end if
Meaning if the check box is on, then pick the lines shown (i.e. 6, 17, etc.)
Go through each line and check the checkbox.
Add 1 to the Rating field. (PROBLEM!!!)

This code repeats per checkbox and should add one for each time the line appears in the list for a checkbox.
I can get it to be "1" if the checkbox is ticked... but not 2, 3, or more if it appears in more than one situation.
I looked into GetDataOfLine, but couldn't get the syntax working... I figured if I could get what the "Rating" number is, I could out it into a variable, add one to it, then dispatch it with … x, "Rating", variable in the second dispatch line.
I just couldn't extract the data of the "Rating" field in the row template...
Hilfe?
Danke.
XdM

Klaus
Posts: 10490
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid Form Sort Column

Post by Klaus » Tue Aug 21, 2018 4:37 pm

Hi Xero,

...
put 6 into theLine
put GetDataOfLine(theLine,"Rating") into the_rating_of_line_6_in_the_datagrid
...
Sorry, don't get the rest, could you please post your script(s)?


Best

Klaus

Xero
Posts: 36
Joined: Sat Jun 23, 2018 2:22 pm

Re: Data Grid Form Sort Column

Post by Xero » Wed Aug 22, 2018 1:28 am

thanks Klaus... that was the script that I was using... when I put it in as such:

10 put GetDataOfLine(x,"Rating") of group "DataGrid 1" of Card "ExerciseCard" into theRating

I get the following error:
button "Get Exercises": compilation error at line 10 (Commands:missing ',') near "into" char 70.
The following code:

10 put GetDataOfLine(x,"Rating") into theRating

gets no error.

here's my set up:
On Card 1, there is a button "Get Exercises". The script is

Code: Select all

on mousedown
   go to card "ExerciseCard"
   send mouseup to button "Get Runity Exercises" of card "ExerciseCard"
   ---new script, faulty---
   if the hilited of button "A" of card "OneVideo" then
      put "3,4,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,23,24,26,30" into tAList
      set the itemdelimiter to comma
      repeat for each item x in TAList
         put GetDataOfLine(x,"Rating") of group "DataGrid 1" of card "ExerciseCard" into theRating
         put theRating + 1 into theRating
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "checked", true
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "Rating", theRating
      end repeat
   end if
   --- old script---
   if the hilited of button "E" of card "OneVideo" then
      put "1,2,4,5,11,12,13,15,16,17,25,26,29" into tAList
      set the itemdelimiter to comma
      repeat for each item x in TAList
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "checked", true
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "Rating", +1
      end repeat
   end if
   --etc. where button "A", "E", etc are check boxes
   dispatch "RefreshList" to group "DataGrid 1" of card "ExerciseCard"
   dispatch "SortDataByKey" to group "DataGrid 1" with "Rating", numeric, descending, false
end mousedown
I have a series of checkboxes on Card 1, and this script checks the "checked" or "not checked" status of them. If a certain box is checked, it checks a box, and should add 1 to the rating. So in the above 2 examples, line 1, 2, and 3 should have "1" in their rating, and line 4 should have "2" in it, because it appears in both lists.

On Card 2 (Called Card "ExerciseCard") there is a DataGrid. It starts blank. One column, form type. The row template has been altered to have a checkbox with label, and a field called "Rating". Also on this card is 2 buttons, one called "Get Pilates Exercises", and one called "Get Runity Exercises". These buttons populate the DataGrid with a different set of exercises per button, and put "0" into the rating and mark the checkboxes as unchecked. All of this, except the Rating field was done as per the working with check boxes tutorial http://lessons.livecode.com/m/datagrid/ ... -data-grid .

The code I used in the behaviour script of the DG row template is:

Code: Select all

on FillInData pDataArray
   set the label of button "Check" of me to pDataArray["label"]
   set the hilited of button "Check" of me to pDataArray["checked"]
   put pDataArray["Rating"] into field "Rating" of me
end FillInData
The script of the button on Card 1 (above) is designed to:
1. Go to Card "ExerciseCard",
2. push the button "Get Runity Exercises" to populate the DG with Runity exercises,
3. see if a box on Card 1 is checked, then check certain boxes on certain lines (the string of numbers comma delimited),
4. add 1 to the rating
5. repeat for all checkboxes on Card 1
6. refresh the DataGrid to show the new numbers
7. Sort the DataGrid so that the highest numbers are at the top.

I have tested everything else, and only the "add 1 to the rating" part is not working...

It seems that I can't GetDataOfLine outside of the DG, or outside of the current card??? Do I need to dispatch it as per the "SetDataOfLine" command?

It's a complex set up, and I prefer not to do complex, but it's the only way I can think to do what I want to do.
If it's too much to picture, I can email you the LC file and point you in the right direction...
XdM

Klaus
Posts: 10490
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid Form Sort Column

Post by Klaus » Wed Aug 22, 2018 12:42 pm

Hi Xero,

I am completely puzzled!?

The only way I got this line:
...
put GetDataOfLine(x,"Rating") of group "DataGrid 1" of Card "ExerciseCard" into theRating
..
compiled without error is this way:
...
put GetDataOfLine(x,"Rating") into theRating
...
???
:shock: :shock: :shock:

Will search my archives for older DG stuff, where I sure have used this...

Klaus
Posts: 10490
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid Form Sort Column

Post by Klaus » Wed Aug 22, 2018 12:52 pm

5 minutes later...

OK, I never used GetDataOfLine etc., I used:
...
put the dgDataOfLine[1] of grp "dg1" into tLine
...
Please try this syntax which will also accept "of grp XYZ of cd zyx..."

And since you ARE on card "Exercxise" no nedd to specify the card anyway, right?
And I would modify the data of the datagrid in one "run" like:

Code: Select all

on mousedown
   go to card "ExerciseCard"
   send "mouseup" to button "Get Runity Exercises" of card "ExerciseCard"
   if the hilited of button "A" of card "OneVideo" then
      put "3,4,6,7,8,9,10,11,12,13,14,15,16,17,19,20,21,23,24,26,30" into tAList
      repeat for each item x in TAList
         put the dgDataOfLine[x] of grp "DataGrid 1" into tData
         add 1 to tData["ranking"]
         put true into tData["checked"]
         set the dgDataOfLine[x] of grp "DataGrid 1" to tData
      end repeat
   end if
...
Should do the trick, hopefully. :D

Best

Klaus

Xero
Posts: 36
Joined: Sat Jun 23, 2018 2:22 pm

Re: Data Grid Form Sort Column

Post by Xero » Wed Aug 22, 2018 1:18 pm

Damn!
You beat me to the punch!!!
I essentially did the same thing, just in a less elegant way...

Code: Select all

   if the hilited of button "BPMNo" of card "OneVideo" then
      put "6,17,19,20,29,30" into tAList
      set the itemdelimiter to comma
      repeat for each item x in TAList
         put the dgDataOfLine[x] of group "DataGrid 1" on Card "ExerciseCard" into theRatingA
         put theRatingA["Rating"]into tRating
         put tRating + 1 into tRating
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "checked", true
         dispatch "SetDataOfLine" to group "DataGrid 1" of card "ExerciseCard" with x, "Rating", tRating
      end repeat
   end if
So simple.
I feel stupid.
It was late last night!
XdM

Klaus
Posts: 10490
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Data Grid Form Sort Column

Post by Klaus » Wed Aug 22, 2018 1:28 pm

I won't tell anyone! :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”