2014-12-02 1 views
0

Я успешно получил свои данные, что составляет более 20000 записей со следующей проблемой code.the, я имею в виду, что мне нужно сортировать их в datagrid по Title.My datagrid - это форма с двумя полями label1, и label2. как можно отсортировать данные по названию?
вот мой кодДанные сортировки Livecode в datagrid

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 

ответ

0

Я обычно более комфортно сортировки в незашифрованном виде, как правило, извлекая «dgData», который будет возвращать вкладку и вернуть текст с разделителями, сортировка, а затем восстановление.

Но вы можете сортировать данные в DataGrid. Ознакомьтесь с Руководством DG на стр.226.

Craig Newman

+0

спасибо but.the ответа не имеет ничего общего с моим question.i знает, как сортировать столбцы в таблице ** DataGrid **, Проблема заключается в том, чтобы разобраться в DataGrid с заголовком в ** Форма Datagrid ** У меня есть команда в моем коде ** в shortme **, но я ничего не получаю – johnnyB

 Смежные вопросы

  • Нет связанных вопросов^_^