Moving lines in a datagrid

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: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Moving lines in a datagrid

Post by DavJans » Tue Mar 21, 2017 6:38 pm

I would like to reorder data in a Data Grid. It it possible, ideally for me, to select for example line 4 and then push a button to move it up to line 3 and have line 3 move down to line 4? (or click and drag? I'm not too worried about this and am probably just dreaming).

I would like to do this so that later I can save that new order into our mysql server as the order that it will populate in later when the data is recalled
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Moving lines in a datagrid

Post by DavJans » Tue Mar 21, 2017 6:57 pm

this works :)

on mouseUp
put the dgDataOfLine[3] of group "DataGridLotList" into tLineData
put the dgDataOfLine[2] of group "DataGridLotList" into tOtherLineData
set the dgDataOfLine[2] of group "DataGridLotList" to tLineData
set the dgDataOfLine[3] of group "DataGridLotList" to tOtherLineData
end mouseUp
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Moving lines in a datagrid

Post by DavJans » Tue Mar 21, 2017 7:10 pm

To move Down I got this.

global sortLineNumber
global totalNumOfLines

on mouseUp
if sortLineNumber < totalNumOfLines then
put sortLineNumber + 1 into otherLineNumber
put the dgDataOfLine[sortLineNumber] of group "DataGridLotList" into tLineData
put the dgDataOfLine[otherLineNumber] of group "DataGridLotList" into tOtherLineData
set the dgDataOfLine[otherLineNumber] of group "DataGridLotList" to tLineData
set the dgDataOfLine[sortLineNumber] of group "DataGridLotList" to tOtherLineData
put sortLineNumber + 1 into sortLineNumber
end if
end mouseUp

To move up I got this.

global sortLineNumber

on mouseUp
if sortLineNumber > 1 then
put sortLineNumber - 1 into otherLineNumber
put the dgDataOfLine[sortLineNumber] of group "DataGridLotList" into tLineData
put the dgDataOfLine[otherLineNumber] of group "DataGridLotList" into tOtherLineData
set the dgDataOfLine[otherLineNumber] of group "DataGridLotList" to tLineData
set the dgDataOfLine[sortLineNumber] of group "DataGridLotList" to tOtherLineData
put sortLineNumber - 1 into sortLineNumber
end if
end mouseUp

Is there a way I haven't found yet to have the highlight also move with the line?
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Moving lines in a datagrid

Post by Klaus » Tue Mar 21, 2017 7:56 pm

Hi DavJans,

if the currently hilited line = sortLineNumber, then add this at the end of your script:

Code: Select all

...
   set the dghilitedlines of group "DataGridLotList" to otherLineNumber
end mouseup
Best

Klaus

DavJans
Posts: 275
Joined: Thu Dec 12, 2013 4:21 pm

Re: Moving lines in a datagrid

Post by DavJans » Wed Mar 22, 2017 5:17 pm

Thank you Klaus, you are the best :)
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Post Reply