datagrid中的Livecode排序数据
我已经用下面的代码成功地获得了超过20000条记录的数据。我遇到的问题是我需要在datagrid中按标题对它们进行排序。我的datagrid是带有两个字段label1和label2的表单。 如何按标题对数据进行排序?datagrid中的Livecode排序数据,livecode,Livecode,我已经用下面的代码成功地获得了超过20000条记录的数据。我遇到的问题是我需要在datagrid中按标题对它们进行排序。我的datagrid是带有两个字段label1和label2的表单。 如何按标题对数据进行排序? 这是我的密码 Global mydbid local sCursorID, sRowCursorID local sRecordFields local sRecordCount on preopenCard resetgrid uiPopulateList
这是我的密码
Global mydbid
local sCursorID, sRowCursorID
local sRecordFields
local sRecordCount
on preopenCard
resetgrid
uiPopulateListGroup
## Initialize the UI
pass preopencard
end preopenCard
command uiPopulateListGroup
## Connect to database and get records
CloseCursor
OpenDatabase
OpenMoviesCursor
## Cache number of records so we can display useful info
## to the user
put revNumberOfRecords(sCursorID) into sRecordCount
## Track time it takes
put the seconds into theStart
lock screen
## Setting the dgNumberOfRecords of a data grid turns on dynamic
## record fetching. Rather than storing the data that is being displayed
## in an internal array the data grid fires off the GetDataForLine message
## in which you return the data for the appropriate line.
set the dgNumberOfRecords of group "DataGrid1" to sRecordCount
unlock screen
end uiPopulateListGroup
on shortme
dispatch "SortDataByKey" to group "DataGrid1" with "title", "text", "descending", "false"
dispatch "RefreshList" to group "DataGrid1"
end shortme
## this message is sent to the Data Grid but we handle it here
## so that you can see all handlers in one spot
command GetDataForLine pLine, @pOutData
## Revolution 3.5 added revMoveToRecord to revDB. This makes it really
## easy to navigate to the proper record for pLine
revMoveToRecord sCursorID, pLine - 1 -- 0 based record navigation
put revDatabaseColumnNumbered(sCursorId, 1) into theRowID
## The rowID is stored in the cursor. Open another cursor that contains all fields for this record.
--put revQueryDatabase(mydbid,"SELECT * FROM datadrinks WHERE rowid = " & theRowID) into sRowCursorID
put revQueryDatabase(mydbid,"select title,content from datadrinks where rowid = " & theRowID ) into sRowCursorID
if sRowCursorID is an integer then
## Now convert record in the row cursor to an array for the data grid
put ConvertCurrentRowToArray() into pOutData
revCloseCursor sRowCursorID
end if
end GetDataForLine
function ConvertCurrentRowToArray
local theArray
if sRecordFields is empty then
## Cache the fields in the cursor in a script local variable.
put revDatabaseColumnNames(sRowCursorID) into sRecordFields
end if
## Converts current record in the cursor into a single dimensional array.
## Note we are using the cached script local sRecordFields
repeat for each item theField in sRecordFields
put revDatabaseColumnNamed(sRowCursorID, theField) into theArray[theField]
end repeat
return theArray
end ConvertCurrentRowToArray
command OpenDatabase
set the wholematches to true
if mydbid is not an integer OR mydbid is not among the items of revOpenDatabases() then
put the filename of this stack into thePath
set the itemdelimiter to slash
put "drinksfull.sqlite" into the last item of thePath
put revOpenDatabase("sqlite",thePath,,,,) into mydbid
if mydbid is not an integer then
answer "Error connecting to the database:" && mydbid & "."
put empty into mydbid
exit to top
end if
end if
end OpenDatabase
command CloseDatabase
try
revCloseDatabase mydbid
catch e
end try
end CloseDatabase
command OpenMoviesCursor
## Selecting 50,000 records can take a bit of time. The method used in this
## example selects the rowid of the 50,000 records and stores that in a cursor.
## In GetDataForLine the rowid is used to fetch the entire record. This is much faster.
//put revQueryDatabase(mydbid,"SELECT rowid FROM datadrinks") into sCursorID
put revQueryDatabase(mydbid,"SELECT rowid FROM datadrinks where centralcat like 'cock%' ") into sCursorID
if sCursorID is not an integer then
answer "Error opening cursor:" && sCursorID & "."
exit to top
end if
end OpenMoviesCursor
command CloseCursor
try
revCloseCursor sCursorID
catch e
end try
end CloseCursor
#command uiViewRecord pID
# put "SELECT * from datadrinks WHERE ID = " & pID into theSQL
# put revDataFromQuery(tab, cr, mydbid, theSQL) into theData
#end uiViewRecord
on resetgrid
send "ResetControl" to group "DataGrid1"
put empty into sRecordFields
put empty into sRowCursorID
put empty into sCursorID
put empty into sRecordCount
end resetgrid
on closeCard
put empty into sRecordFields
## Close the database connection as we don't need it any longer
CloseDatabase
end closeCard
我通常更习惯于以清晰的方式排序,通常提取“dgData”,它将返回制表符并返回分隔文本、排序,然后恢复 但是您可以在数据网格内部进行排序。查看第226页上的DG指南
Craig Newman谢谢,但答案与我的问题无关。我知道如何对datagrid表中的列进行排序,问题是如何使用datagrid表单中的标题对datagrid进行排序我的代码中有shortme命令,但我什么也没有得到