cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting a SAP Table ?

Former Member
0 Kudos

Hi,

can anyone of you give me a detailed example for how to accomplich sorting in a datatable. The DatSource is a DataView.

Regards

Erhan

Accepted Solutions (1)

Accepted Solutions (1)

reiner_hille-doering
Active Contributor
0 Kudos

What do you want to sort. From the subject "SAP Table" I would assume that you would like to sort an instance of a class that is created by the Proxy Generator and inherits from SAPTable. These have nice sorting feature in both the public method "SortBy(columnName, direction) and the functions and properties inherited from Microsoft's interface IBindingList. All is documented in NCo 2.0 online help.

If you copy your SAP table to a DataSet, you can use the sorting feature of DataView. The only question is why you would like to do so, because it only needs more time. SAP Tables have all needed databinding and sorting features already built-in.

Former Member
0 Kudos

Hi Reiner,

there has been a missunderstanding.

When I did talk about a SAP Table, i just meant the Sap.Web.Control in PDK.Net.

The Datasource of this Control is a DataView.

I think I am by now on the right way, when I am trying to sort the Dataview, so the SAP Table has been sorted too.

reiner_hille-doering
Active Contributor
0 Kudos

> When I did talk about a SAP Table, i just meant the

> Sap.Web.Control in PDK.Net.

Ah, I see.

> I think I am by now on the right way, when I am

> trying to sort the Dataview, so the SAP Table has

> been sorted too.

Exactly. There should be also a sample in the references docu of the Table control at the "Sort" event (at least there have been one in the past...):

If the datasource implements a sorting feature - usually exposed by the interface IBindingList - the sorting can be easily accomplished with the following code snipped:

private void Table1_Sort(object sender, SAP.Web.UI.Controls.Table.SortEventArgs e)

{

IBindingList bl = e.DataSource as IBindingList;

if (bl != null && bl.SupportsSorting && bl.Count > 0)

bl.ApplySort(TypeDescriptor.GetProperties(bl[0])[e.SortColumn.Title], e.SortDirection);

}

Former Member
0 Kudos

Reinier,

when I use the IBindingList I allways get the following Error:

Server Error in '/EPApp1400' Application.

-


Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]

System.Data.DataView.System.ComponentModel.IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection direction)

KWGLaufverfolgung_IView.KWGLaufverfolgung_Anzeigen.tblErgebnis_Sort(Object sender, SortEventArgs e)

SAP.Web.UI.Controls.Table.OnDataBinding(EventArgs e)

System.Web.UI.Control.DataBind()

KWGLaufverfolgung_IView.KWGLaufverfolgung_Anzeigen.Page_Load(Object sender, EventArgs e)

System.Web.UI.Control.OnLoad(EventArgs e)

SAP.Portal.Web.UI.PortalComponent.OnLoad(EventArgs e)

System.Web.UI.Control.LoadRecursive()

System.Web.UI.Control.LoadRecursive()

System.Web.UI.Control.LoadRecursive()

System.Web.UI.Page.ProcessRequestMain()

-


Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

1. Do I have to do s.th. with the Interface before I can use it?

2. Why does the table_sort event fire, when I start the Application?

reiner_hille-doering
Active Contributor
0 Kudos

The exception happens because

"TypeDescriptor.GetProperties(bl[0])[e.SortColumn.Title]"

returns "null".

To shortly explain the "magic" in this code snipped:

IBindingList.ApplySort needs a so-called PropertyDesciptor that describes the column that should be sorted.

We pass the first line to of the datasource to TypeDescriptor.GetProperties() and get a collection of property desciptors - in fact a list of columns.

Now we need to know which of the columns the user clicked for sorting. In the event argument "e.SortColumn" you get some information, and the code just assumes the the title sting of the selected column is also the technical name of the column. This is not allways the case: e.g. you have a Column with titel "User name", but the property is actually called "Username". Therefore the code would fail.

You need to do the mapping from the information you get in "e.SortColumn" to the property name that you pass to indexer of the PropertyDescriptorCollection.

Former Member
0 Kudos

After mapping the ColumnNames it works fine.

Thank you very much so far

Now I do have an other problem.

My DataSet is generated dynamically, so I do not know how many columns my Dataset will contain.

In the beginning there are 3 TableCells declared in my program. Sorting with those TableCell is possible, but when I try to sort the other ones, it gives me an error:

Server Error in '/EPApp1400' Application.

-


Specified argument was out of the range of valid values. Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

Parameter name: Index was out of range. Must be non-negative and less than the size of the collection.]

System.Collections.CollectionBase.System.Collections.IList.get_Item(Int32 index)

SAP.Web.UI.Controls.TableColumnCollection.get_Item(Int32 index)

SAP.Web.UI.Controls.TableCellCollection.get_Item(Int32 index)

SAP.Web.UI.Controls.Table.SortColumn(Int32 columnIdx)

SAP.Web.UI.Controls.TableHeaderCell.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

System.Web.UI.Page.ProcessRequestMain()

-


Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Any suggestions ?

reiner_hille-doering
Active Contributor
0 Kudos

Hm, it seems that someting is inconsisten inside of the Table's internal collections. How do you manage the dynamic behavior of your datasource? Do you handle some of the ItemCreated/ItemsDatabound events by yourself? Or do you changed the ItemTemplate accordingly?

Unfortunately I'm not so deep inside of the code anymore - the colleges have changed quite a bit and introtuced some dynamic databinding feature. Are you using this? If yes, hopefully Ofer can help you.

Former Member
0 Kudos

Hi Reiner,

I dont use any events like ItemCreated/ItemDatabound ....

What I do have is the following. In my HTML Code there is the following code snippet:

<sap:table id="tblErgebnis" SelectionMode="NONE" visibleRowCount="10" runat="server" AutoGenerateColumns="True">

<sap:Caption Text="KWG Laufverfolgung" ID="caption1"></sap:Caption>

<sap:TableRow ID="tblErgebnis_ItemTemplate">

<sap:TableCell ID="tblErgebnis_Column0" SortState="NONE" Title="Column0">

<sap:TextView ID="textView1" Text='<%# DataBinder.Eval(Container.Parent, "DataSourceRow.DataItem.Column0") %>'>

</sap:TextView>

</sap:TableCell>

</sap:TableRow>

</sap:table>

What happens here. This Code gives me the possibility, to sort only the first Column of the programmtically filled table. It is not possible to sort the other 17 Columns. I assume, that if I would have inserted all columns in the html code, i would have get the expected result, but I dont. I dont want to do s.th. static like this. What, if there is another query result, which delivers more than 18 Columns?

Do you have any idea?

Erhan

reiner_hille-doering
Active Contributor
0 Kudos

This looks like a bug in the new AutoGenerateColumns feature. Could you please of an OSS support ticket?

Former Member
0 Kudos

Hi Reiner,

Could you please describe how to create and send a ticket?

Im very new to this forum, and SAP Netweaver.

Thanks.

reiner_hille-doering
Active Contributor
0 Kudos

SAP has a support system called OSS that has a SAPGUI and Web interface (called Service Marketplace). SAP customers have an account to open support tickets. You have to specify a so-called component, which is in your case BC-OP-NET-ASP.

Former Member
0 Kudos

OK Reiner,

thank you very much so far. I will contact some of my Collegues to get further information about the Support Ticket.

I have rated your help with 10 Points.

Regardings

Erhan

Former Member
0 Kudos

Hi Erhan,

Note that the Component to open the bug on is :

"EP-PIN-DNT"

Regards,

Ofer

Former Member
0 Kudos

Hi Ofer,

my colleque said that we are still waiting for an Enterprise Portal ID or s.th. like that, in order to be able to use OSS....

Answers (0)