cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting in Table

former_member209118
Participant
0 Kudos

hi Expert,

I have a table with 4 columns. I'm showing color in one of the column in my table. I'm changing the color in table based on input field. I want to sort based on color. How can I do that.

Thanks,

Ashok.

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

<table:Table rows="{

    path: '/table',

    sorter: [{

        path: '<colorCodeField>',

        descending: false

    }]

}">

Try This...

former_member182862
Active Contributor
0 Kudos

I have provided you the answer in another thread (apart from your main question). Now, you can asking the same thing here. And JSBin sample is provided. Sorry I do not understand how to support you.

former_member209118
Participant
0 Kudos

Hi dennis,

Sorry its not working for me.

the following code that I written in my handle change event.

var oSorter = new sap.ui.model.Sorter('color');

oSorter.fnCompare = function(a,b) {

  if (a === b) {

    return 0;

  }

Thanks,

Ashok.

former_member182862
Active Contributor
0 Kudos

Hi Ashok

Then write the sample code in JSBin like what people are asking for. It is easier for everyone.

We are ready to help you. However, you have to provide sample code for us to help you.

Thanks

-D

former_member209118
Participant
0 Kudos

var oBarCodeValue = this.getView().byId('idBarCode').getValue();

  var data = this.getView().getModel('tableModel').getData().results;

  var oLength = this.getView().getModel('tableModel').getData().results.length;

  for(i=0;i<oLength;i++){

  var oBarValue = this.getView().byId('idTable').getItems()[i].getCells()[1].getText();

  if(oBarCodeValue === oBarValue){

  var oColor = this.getView().byId('idTable').getItems()[i].getCells()[0];

  oColor.setColor('#00FF00');

  this.getView().byId('idTable').getItems()[i].getCells()[1].setState('Success');

  this.getView().byId('idTable').getItems()[i].getCells()[2].setState('Success');

  this.getView().byId('idTable').getItems()[i].getCells()[3].setState('Success');

  }

  var oColorValue = this.getView().byId('idTable').getItems()[i].getCells()[0].getColor();

  var oSorter = new sap.ui.model.Sorter('Color');

  oSorter.fnCompare = function(a,b) {

   if (a === b) {

     return 0;

   }

  }

  }

former_member182862
Active Contributor
0 Kudos

Here is the jsbin sample

JS Bin - Collaborative JavaScript Debugging

Please tell me what is/are not working.

In your sample, there are many unrelated code and you create sorter and sorter is not used.

Please spend some time reading about SAPUI5. It will help you in the long run.

-D

santhu_gowdaz
Active Contributor
0 Kudos

If you put your code in JSBIN is better to solve your problem.

former_member209118
Participant
0 Kudos

Hi,

How can I post my code in jsbin.

Thanks,

Ashok.

santhu_gowdaz
Active Contributor
0 Kudos

Please open ui5 overview page and go through SCN Rules and tips.

or else use Plunker

Former Member
0 Kudos

Step 1 - > JS Bin - Collaborative JavaScript Debugging and login with your ID.


Step 2 -> Type your code HTML JS and CSS


Step 3 -> In write corner there will be Bin Info. Click on that


Step 4 -> Cick clone and copy URL and post here.