SortingMode=ClientSide problems

Posts   
 
    
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 26-Feb-2008 16:30:41   

I am using version 2.5 december 5th build. I am binding a gridview to the LLBLGenDataSource2 control and I am having problems sorting on fields that are added to the datatable after FetchTypedList is called. I set liveperistance to false and subscribed to the perform select event so after FetchTypedList is called I can add a column to the datatable to add additional data. When I try to sort the grid by that column I get the excecption - Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityProperty' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2'.

I have already set the LLBLGenDataSource2 to SortingMode=ClientSide but I still get the exception. If I don't pass the e.Sorter to the FetchTypedList method of the adapter I don't get the exception however nothing gets sorted. What am I doing wrong?

Can some one explain how to sort on SortingMode=Client side when using LivePersistence="False"

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Feb-2008 21:30:34   

In this case you should add a SortClause using EntityProperty. Something like this:

Dim MySort As New SortExpression
MySort.Add(New SortClause(New EntityProperty("YourNewColumn"), Nothing, SortOperator.Ascending))
LLBLGenProDataSource2.SorterToUse = MySort

You could see the manual for more details. wink

David Elizondo | LLBLGen Support Team
Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 26-Feb-2008 22:11:14   

daelmo wrote:

In this case you should add a SortClause using EntityProperty. Something like this:

Dim MySort As New SortExpression
MySort.Add(New SortClause(New EntityProperty("YourNewColumn"), Nothing, SortOperator.Ascending))
LLBLGenProDataSource2.SorterToUse = MySort

You could see the manual for more details. wink

In the performselect method after the button has been pressed, that exact sort expression is already added to the e.Sorter with out me having to add it manuall. Are you are suggesting that I create a SortExpression object and assign it to the SorterToUse property of the datasource control before the PerformSelect is called and this will somehow override the default behavior which correctly populates the sorter with the sort expression to pass to the PerformSelect event? If this is the case do i still pass the e.Sorter to the FetchTypedList method. The manual isn't clear because it doesn't show an example of using LivePersistence="False", SortingMode="ClientSide" and implementing the PerformSelect event.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 27-Feb-2008 00:12:45   

how exactly are you adding the fields to the datatable? Can you paste a code snippet?

Brandt
User
Posts: 142
Joined: 04-Apr-2007
# Posted on: 27-Feb-2008 02:01:18   

goose wrote:

how exactly are you adding the fields to the datatable? Can you paste a code snippet?

Sure thing


        protected void DS_OnCallSchedules_PerformSelect(object sender, PerformSelectEventArgs2 e)
        {
            e.Filter.PredicateExpression.Add(ScheduleFields.EndTime > DateTime.UtcNow);
            using (IDataAccessAdapter adapter = InfrastructureCentral.BLServices.Adapters.InfrastructureCentral)
            {
                adapter.FetchTypedList(e.ContainedTypedList, e.Filter.PredicateExpression, e.MaxNumberOfItemsToReturn, e.Sorter, e.AllowDuplicates, e.PageNumber, e.PageSize);

                DataTable dt = e.ContainedTypedList as DataTable;
                if (!dt.Columns.Contains("MemberName"))
                {
                    dt.Columns.Add("MemberName", typeof(System.String));
                }
                foreach (DataRow dr in dt.Rows)
                {
                    var individualContactGuid = (Guid)dr[DAL.UpCommingOnCallSchedulesForSupportGroupTypedListFieldIndex.IndividualContactGuid.ToString()];
                    var member = (from m in this._supportGroupMembers.Items
                                  where m.ContactGuid == individualContactGuid
                                  select m).First();
                    dr["MemberName"] = member.Name;
                }
                dt.AcceptChanges();

            }
        }

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 27-Feb-2008 11:05:40   

Dim MySort As New SortExpression MySort.Add(New SortClause(New EntityProperty("YourNewColumn"), Nothing, SortOperator.Ascending))

Don't use the e.Sorter Rather pass the above mentioned SortExpression to the FetchTypesList method.

adapter.FetchTypedList(e.ContainedTypedList, e.Filter.PredicateExpression, e.MaxNumberOfItemsToReturn, MySort, e.AllowDuplicates, e.PageNumber, e.PageSize);