cancel
Showing results for 
Search instead for 
Did you mean: 

Table sorting

RiabovAleksandr
Product and Topic Expert
Product and Topic Expert
0 Kudos
858

Hello colleagues,

please advise.

I'm trying to have a simple sorting by column value.

1. The table is created like this:


var oTable = new sap.ui.table.Table({

  id: "Overview",

  title : "Table1",    

  });

2. Then I add a column:


oTable.addColumn(new sap.ui.table.Column({

  label : new sap.ui.commons.Label({text : "Column1"}),

  template : new sap.ui.commons.TextView().bindProperty("text","SENDER_NAME"),

   sortProperty : "SENDER_NAME",

   filterProperty : "SENDER_NAME",

  }));

3. Assign oData model:


oTable.setModel(oController.oModel);

4. Create Sorter:


var sort1 = new sap.ui.model.Sorter("P8_TOTAL");

5.Bind rows of Model to oTable


oTable.bindRows("/DASHBOARDSet",sort1);

6.Return table to View


  return oTable;

Seems like piece a cake, but it is not working.

No idea why. I've read many threads here and couldn't make it work.

Appreciate your help.

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Alex, SAP just came up with client side sorting/filtering for OData model in 1.28:

The first steps towards client-side filtering/sorting on OData Model Data: the final implementation is planned for a later release, but a first experimentalversion is available in 1.28: by setting the “OperationMode" on a list binding to "Client", you can force the OData model to loadall data from the server and do sorting and filtering entirely in the browser, with no server roundtrip. Useful only when it is guaranteed that the count of data elements is low.

So, if you need client side sorting/filtering - use JsonModel as suggested before

Answers (2)

Answers (2)

Former Member
0 Kudos
former_member104848
Participant
0 Kudos

Hello Alexander,

What behavior are you exactly observing?

When the data is rendered in the table, by default the sorting would be applied on 'P8_TOTAL'.

When you sort on the Column that you have added, there should be a call to the backend for sorting on SENDER_NAME ($orderby = SENDER_NAME asc)

Regards

Radhika

RiabovAleksandr
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Radhika,

thanks for reply.

Actually I'm expecting to have a table with several columns and user can sort + filter ascending and descending by any column.

Isn't it possible without backend re-fetch?

Thank you.

santhu_gowdaz
Active Contributor
0 Kudos

Hi Alexander,

May u r using oData Model, so every sort and filter its triggered back end. use JSON model insted of oData model.

RiabovAleksandr
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Santhosh,

thanks for reply.

Do you have any example of just copying oData model to JSON model?

I just need direct copy from one to another without any filter, sorting, etc

Thank you

santhu_gowdaz
Active Contributor
0 Kudos

Hi Alexander,

i'm using this code, Replace ur oData Model to this,

$.ajax({  

url : YOUR_URL,
jsonpCallback : 'getJSON',  
contentType : "application/json",  
dataType : 'json',  
success : function(data, textStatus, jqXHR)
{  
var oModel1 = new sap.ui.model.json.JSONModel();
oModel1.setData(data);
var aData = oModel1.getProperty("/d/results");  
oModel1.setData({ modelData : aData });
  table.setModel(oModel1, "odata");
table.bindAggregation("items","odata>/modelData", that);
// 

},

});

former_member182372
Active Contributor
0 Kudos

Here is just one of the way, adjust accordingly. Success call back function parameter has results variable which contains a data from OData call, so just slice and dice it, or just copy as is


new sap.ui.model.json.JSONModel(oEvent.results)


try {

  oModel.read("/StatusSet", null, null, true, function(oEvent) {

  var map = [];

  var list = [];

  $.each(oEvent.results, function(i, item) {

  list.push({

  "Status" : item.StatusNum,

  "Description" : item.Description

  });

  map[item.StatusNum] = item.Description;

  });

  var jModel = new sap.ui.model.json.JSONModel({

  "map" : map,

  "list" : list

  });

  sap.ui.getCore().setModel(jModel, "StatusModel");

  sap.ui.getCore().getEventBus().publish("app", "StatusModelLoaded");

  }, function(oError) {

  jQuery.sap.log.error("An error occurred while processing StatusSet");

  });

} catch (oError) {

  jQuery.sap.log.error("An error occurred while processing StatusSet");

}