Skip to main content

Persist filter and keep filter expanded

Many of you have problably seen these blog posts

Persisting Filter conditions in EP Grid
http://blogs.msdn.com/b/epblog/archive/2009/08/29/persisting-filter-conditions-in-ep-grid.aspx

and

Always keep the Filter section expanded in AxGridView
http://community.dynamics.com/product/ax/axtechnical/b/axsolutionsmonkey/archive/2009/04/02/always-keep-the-filter-section-expanded-in-axgridview.aspx

They are excelent to use togather i.e. persist the filter and keep the filter open as well

I implemented two static methods in the EP class to persist the filter, then i can use oneliners to persist the filter of any dataset.

Also have in mind that if the PersistState of the ASP.NET dataset is set to false the filter is not persisted. So check out that the property is set to true, it is true by default







public static void packDataSet(Name _name, container _value, QueryRun _queryRun)
{
    SysLastValue    sysLastValue;
    ;

    ttsbegin;
    // Delete last saved query for the current dataset

    delete_from sysLastValue
        where sysLastValue.Company      == curext()
           && sysLastValue.UserId       == curuserid()
           && sysLastValue.RecordType   == UtilElementType::DataSet
           && sysLastValue.elementName  == _name
           && sysLastValue.DesignName   == _name;

    // If there is a new queryRun() object then serialize and save it
    // in the sys last value table
    // Put your datasource name


    if (_queryRun)
    {
        sysLastValue.RecId = 0;
        sysLastValue.Company        = curext();
        sysLastValue.UserId         = curuserid();
        sysLastValue.RecordType     = UtilElementType::DataSet;
        sysLastValue.ElementName    = _name;
        sysLastValue.DesignName     = _name;
        sysLastValue.value          =  _value;
        sysLastValue.insert();
    }

    ttscommit;
}



public static void unPackDataSet(Name _name, Query _query)
{
    SysLastValue    sysLastValue;
    Query           savedQuery;
    ;

    // get the last value from the sys last value table
    select firstonly sysLastValue
        where sysLastValue.Company      == curext()
           && sysLastValue.UserId       == curuserid()
           && sysLastValue.RecordType   == UtilElementType::DataSet
           && sysLastValue.ElementName  == _name
           && sysLastValue.DesignName   == _name;

    if (sysLastValue && sysLastValue.Value)
    {
       
// If there is an unpack error delete the saved query

        if (!SysQuery::unpackRangeAndSortorder(_query, sysLastValue.value))
        {
            ttsbegin;

            delete_from sysLastValue
                where sysLastValue.Company      == curext()
                   && sysLastValue.UserId       == curuserid()
                   && sysLastValue.RecordType   == UtilElementType::DataSet
                   && sysLastValue.ElementName  == _name
                   && sysLastValue.DesignName   == _name;

           ttscommit;
        }
    }
}

Comments