Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Sorting in CExtGridDataProviderRecordset Collapse All
Subject Author Date
Petr Hajny Mar 19, 2006 - 3:51 AM

Hi!
I need to use my own data provider that loads data from PostgreSQL. I’m using a class derived from CExtGridDataProviderRecordset which works fine. What I need is to implement sorting when a header cell is clicked on.
I think I must override SortOrderGet/Set/Update functions so that the whole content of my cache data provider is filled first.
Can anybody help me, please?
Thanx!

Bahrudin Hrnjica Mar 19, 2006 - 5:39 AM

I had the same problem few days ago, and I fixed it by overriding, SortOrderUpdate, SortOrderSet, SortOrderGet. The following code shows you my implementation.

P.S. I am using ADO, and it works on SQL and jet engine

bool CBHExtADOProvider::SortOrderUpdate(
    bool bColumns, // true = sort order for columns, false - for rows
    CExtGridDataProvider::IDataProviderEvents * pDPE // = NULL
    )
{
    CString strSort;

    CString strOrder;
    bstr_t strFieldName;
    CString strComma;

    if(!bColumns)
    {
        ASSERT_VALID( this );
        LONG nCount = (LONG)m_gdsoRows.m_arrItems.GetSize();
        if( nCount == 0L )
            return true;

        LONG nSize = bColumns ? RowCountGet() : ColumnCountGet();

        ASSERT( nSize >= 0L );

        for( LONG i = 0L; i < nCount; i++ )
        {
            LONG nCol=m_gdsoRows.m_arrItems[i].m_nRowColNo;
            nCol--;
            strFieldName=m_objAdoRS->Fields->Item[nCol]->Name;

            if(m_gdsoRows.m_arrItems[i].m_bAscending)
                strOrder="ASC";
            else
                strOrder="DESC";
            if(i+1<nCount)
                strComma=",";
            else
                strComma=" ";

            USES_CONVERSION;
            CString strName = OLE2CT(strFieldName);

            strSort+="["+strName+"]"+" "+strOrder+strComma;

            m_objAdoRS->PutSort(bstr_t(strSort));
                
        }
    }
    return true;

}

bool CBHExtADOProvider::SortOrderSet(
    const CExtGridDataSortOrder & _gdso,
    bool bColumns, // true = sort order for columns, false - for rows
    CExtGridDataProvider::IDataProviderEvents * pDPE // = NULL
    )
{
    ASSERT_VALID( this );
    if( ! _gdso.ItemsUnique() )
    {
        // sort order must have unique row/column indices
        ASSERT( FALSE );
        return false;
    }
    if( ! _SortOrderCheck( _gdso, bColumns ) )
        return false;
    if( bColumns )
    {
        if( _gdso == m_gdsoColumns )
            return true;
        m_gdsoColumns = _gdso;
    } // if( bColumns )
    else
    {
        if( _gdso == m_gdsoRows )
            return true;
        m_gdsoRows = _gdso;
    } // else from if( bColumns )
    VERIFY( SortOrderUpdate( bColumns, pDPE ) );
    return true;
}

bool CBHExtADOProvider::SortOrderGet(
    CExtGridDataSortOrder & _gdso,
    bool bColumns // true = sort order for columns, false - for rows
    ) const
{
    ASSERT_VALID( this );
    if( bColumns )
        _gdso = m_gdsoColumns;
    else
        _gdso = m_gdsoRows;
    ASSERT( _gdso.ItemsUnique() );
    return true;
}


If my code will help you,i will be glad.

Technical Support Mar 20, 2006 - 2:58 AM

We would like just to add some additional comments to this thread. To redirect SortOrderSet() to SortOrderUpdate() is a correct and suitable solution in case of a cacheable data provider because any change in sorting rule leads to rebuilding of SQL. If the grid window is enabled for editing, SortOrderUpdate() will be invoked at the end of the each cell editing session. If you need to forcibly reload the visible cache of rows, then you need to invoke the grid’s CExtScrollItemWnd::SiwFireCacheChanging() method.