Data Grid Form Sort Column
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Data Grid Form Sort Column
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
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 (14.23 KiB) Viewed 4782 times
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Data Grid Form Sort Column
Hi Xero,
check "SortDataByKey" in the dictionary, that case also be used with datagrid FORMS!
Best
Klaus
check "SortDataByKey" in the dictionary, that case also be used with datagrid FORMS!
Best
Klaus
Re: Data Grid Form Sort Column
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:
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
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
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
Re: Data Grid Form Sort Column
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
...
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
Re: Data Grid Form Sort Column
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
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:
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
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
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
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
Re: Data Grid Form Sort Column
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
...
???
Will search my archives for older DG stuff, where I sure have used this...
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
...
???
Will search my archives for older DG stuff, where I sure have used this...
Re: Data Grid Form Sort Column
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:
Should do the trick, hopefully.
Best
Klaus
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
...
Best
Klaus
Re: Data Grid Form Sort Column
Damn!
You beat me to the punch!!!
I essentially did the same thing, just in a less elegant way...
So simple.
I feel stupid.
It was late last night!
XdM
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
I feel stupid.
It was late last night!
XdM
Re: Data Grid Form Sort Column
I won't tell anyone!