how to apply sorting in ui-grid?












0















I have one angularjs project in which I am using ui-grid.



As you can see in my code, I have some attribute in cell-template. I have to perform sorting based on "rating-percentage".



So I am trying to write a sorting algorithm which required row.entity property.



My question is that how can I add rating percentage in row.entity.



What is the right way to perform sorting using "rating-percentage"?



Below is my code:



 define([
'angular'
], function (angular) {

function SelectToolController($scope, $timeout, $filter) {
var vm = this,
_gridApi,
_cellTemplate,
_columnDefs,
_starRatingTemplate,
_starRatingColumn;

_starRatingTemplate =[
'<div class="ui-grid-cell-contents ">',
'<div class="opr-star-rating" >',
'<opr-star-rating rating-percentage="{{rowRenderIndex}}"',
'total-count="23"',
'suffix-display="true"',
'rating-display="true"',
'count-display="22">',
'</opr-star-rating>',
'</div>',
'</div>'
].join('');

_starRatingColumn = {
name: 'starRating',
cellTemplate: _starRatingTemplate,
displayName: 'Rating',
enableFiltering: false,
enableSorting: true,
cellClass: 'star-column',
enableHiding: false,
enableRowSelection: true,
}
_columnDefs.push(_starRatingColumn);

})();









share|improve this question



























    0















    I have one angularjs project in which I am using ui-grid.



    As you can see in my code, I have some attribute in cell-template. I have to perform sorting based on "rating-percentage".



    So I am trying to write a sorting algorithm which required row.entity property.



    My question is that how can I add rating percentage in row.entity.



    What is the right way to perform sorting using "rating-percentage"?



    Below is my code:



     define([
    'angular'
    ], function (angular) {

    function SelectToolController($scope, $timeout, $filter) {
    var vm = this,
    _gridApi,
    _cellTemplate,
    _columnDefs,
    _starRatingTemplate,
    _starRatingColumn;

    _starRatingTemplate =[
    '<div class="ui-grid-cell-contents ">',
    '<div class="opr-star-rating" >',
    '<opr-star-rating rating-percentage="{{rowRenderIndex}}"',
    'total-count="23"',
    'suffix-display="true"',
    'rating-display="true"',
    'count-display="22">',
    '</opr-star-rating>',
    '</div>',
    '</div>'
    ].join('');

    _starRatingColumn = {
    name: 'starRating',
    cellTemplate: _starRatingTemplate,
    displayName: 'Rating',
    enableFiltering: false,
    enableSorting: true,
    cellClass: 'star-column',
    enableHiding: false,
    enableRowSelection: true,
    }
    _columnDefs.push(_starRatingColumn);

    })();









    share|improve this question

























      0












      0








      0








      I have one angularjs project in which I am using ui-grid.



      As you can see in my code, I have some attribute in cell-template. I have to perform sorting based on "rating-percentage".



      So I am trying to write a sorting algorithm which required row.entity property.



      My question is that how can I add rating percentage in row.entity.



      What is the right way to perform sorting using "rating-percentage"?



      Below is my code:



       define([
      'angular'
      ], function (angular) {

      function SelectToolController($scope, $timeout, $filter) {
      var vm = this,
      _gridApi,
      _cellTemplate,
      _columnDefs,
      _starRatingTemplate,
      _starRatingColumn;

      _starRatingTemplate =[
      '<div class="ui-grid-cell-contents ">',
      '<div class="opr-star-rating" >',
      '<opr-star-rating rating-percentage="{{rowRenderIndex}}"',
      'total-count="23"',
      'suffix-display="true"',
      'rating-display="true"',
      'count-display="22">',
      '</opr-star-rating>',
      '</div>',
      '</div>'
      ].join('');

      _starRatingColumn = {
      name: 'starRating',
      cellTemplate: _starRatingTemplate,
      displayName: 'Rating',
      enableFiltering: false,
      enableSorting: true,
      cellClass: 'star-column',
      enableHiding: false,
      enableRowSelection: true,
      }
      _columnDefs.push(_starRatingColumn);

      })();









      share|improve this question














      I have one angularjs project in which I am using ui-grid.



      As you can see in my code, I have some attribute in cell-template. I have to perform sorting based on "rating-percentage".



      So I am trying to write a sorting algorithm which required row.entity property.



      My question is that how can I add rating percentage in row.entity.



      What is the right way to perform sorting using "rating-percentage"?



      Below is my code:



       define([
      'angular'
      ], function (angular) {

      function SelectToolController($scope, $timeout, $filter) {
      var vm = this,
      _gridApi,
      _cellTemplate,
      _columnDefs,
      _starRatingTemplate,
      _starRatingColumn;

      _starRatingTemplate =[
      '<div class="ui-grid-cell-contents ">',
      '<div class="opr-star-rating" >',
      '<opr-star-rating rating-percentage="{{rowRenderIndex}}"',
      'total-count="23"',
      'suffix-display="true"',
      'rating-display="true"',
      'count-display="22">',
      '</opr-star-rating>',
      '</div>',
      '</div>'
      ].join('');

      _starRatingColumn = {
      name: 'starRating',
      cellTemplate: _starRatingTemplate,
      displayName: 'Rating',
      enableFiltering: false,
      enableSorting: true,
      cellClass: 'star-column',
      enableHiding: false,
      enableRowSelection: true,
      }
      _columnDefs.push(_starRatingColumn);

      })();






      angularjs angular-ui-grid ui-grid






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 4:44









      Anubha GuptaAnubha Gupta

      469




      469
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can define your custom sorting function then link this function to column definition.



           $scope.sortFun=function(a, b) { 
          ///.... your logic
          }

          _starRatingColumn = {
          name: 'starRating',
          cellTemplate: _starRatingTemplate,
          displayName: 'Rating',
          enableFiltering: false,
          enableSorting: true,
          cellClass: 'star-column',
          enableHiding: false,
          enableRowSelection: true,
          'sortingAlgorithm': $scope.sortFun
          }


          change your template.



          '<div class="ui-grid-cell-contents ">',
          '<div class="opr-star-rating" ng-class="col.colIndex() >',
          '<opr-star-rating rating-percentage="{{row.entity}}"',
          'total-count="23"',
          'suffix-display="true"',
          'rating-display="true"',
          'count-display="22">',
          '</opr-star-rating>',
          '</div>',
          '</div>'





          share|improve this answer


























          • actually, what I am not able to understand is, how to get the value of ratingPercentage in sorting function?

            – Anubha Gupta
            Nov 20 '18 at 5:06











          • change cell template according to this.

            – Sameer
            Nov 20 '18 at 5:33











          • It is not recognizing col property itself

            – Anubha Gupta
            Nov 20 '18 at 6:02











          • you can also use row.entity. you rating-percentage attribute will receive complete object of array result

            – Sameer
            Nov 20 '18 at 6:04













          • Yes I am trying with row.entity only. Problem is that it is not getting any of attribute mentioned in cellTemplate in row.entity. I am trying to get rating-percentage in row.entity. But no luck!

            – Anubha Gupta
            Nov 20 '18 at 6:06











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386381%2fhow-to-apply-sorting-in-ui-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can define your custom sorting function then link this function to column definition.



           $scope.sortFun=function(a, b) { 
          ///.... your logic
          }

          _starRatingColumn = {
          name: 'starRating',
          cellTemplate: _starRatingTemplate,
          displayName: 'Rating',
          enableFiltering: false,
          enableSorting: true,
          cellClass: 'star-column',
          enableHiding: false,
          enableRowSelection: true,
          'sortingAlgorithm': $scope.sortFun
          }


          change your template.



          '<div class="ui-grid-cell-contents ">',
          '<div class="opr-star-rating" ng-class="col.colIndex() >',
          '<opr-star-rating rating-percentage="{{row.entity}}"',
          'total-count="23"',
          'suffix-display="true"',
          'rating-display="true"',
          'count-display="22">',
          '</opr-star-rating>',
          '</div>',
          '</div>'





          share|improve this answer


























          • actually, what I am not able to understand is, how to get the value of ratingPercentage in sorting function?

            – Anubha Gupta
            Nov 20 '18 at 5:06











          • change cell template according to this.

            – Sameer
            Nov 20 '18 at 5:33











          • It is not recognizing col property itself

            – Anubha Gupta
            Nov 20 '18 at 6:02











          • you can also use row.entity. you rating-percentage attribute will receive complete object of array result

            – Sameer
            Nov 20 '18 at 6:04













          • Yes I am trying with row.entity only. Problem is that it is not getting any of attribute mentioned in cellTemplate in row.entity. I am trying to get rating-percentage in row.entity. But no luck!

            – Anubha Gupta
            Nov 20 '18 at 6:06
















          0














          You can define your custom sorting function then link this function to column definition.



           $scope.sortFun=function(a, b) { 
          ///.... your logic
          }

          _starRatingColumn = {
          name: 'starRating',
          cellTemplate: _starRatingTemplate,
          displayName: 'Rating',
          enableFiltering: false,
          enableSorting: true,
          cellClass: 'star-column',
          enableHiding: false,
          enableRowSelection: true,
          'sortingAlgorithm': $scope.sortFun
          }


          change your template.



          '<div class="ui-grid-cell-contents ">',
          '<div class="opr-star-rating" ng-class="col.colIndex() >',
          '<opr-star-rating rating-percentage="{{row.entity}}"',
          'total-count="23"',
          'suffix-display="true"',
          'rating-display="true"',
          'count-display="22">',
          '</opr-star-rating>',
          '</div>',
          '</div>'





          share|improve this answer


























          • actually, what I am not able to understand is, how to get the value of ratingPercentage in sorting function?

            – Anubha Gupta
            Nov 20 '18 at 5:06











          • change cell template according to this.

            – Sameer
            Nov 20 '18 at 5:33











          • It is not recognizing col property itself

            – Anubha Gupta
            Nov 20 '18 at 6:02











          • you can also use row.entity. you rating-percentage attribute will receive complete object of array result

            – Sameer
            Nov 20 '18 at 6:04













          • Yes I am trying with row.entity only. Problem is that it is not getting any of attribute mentioned in cellTemplate in row.entity. I am trying to get rating-percentage in row.entity. But no luck!

            – Anubha Gupta
            Nov 20 '18 at 6:06














          0












          0








          0







          You can define your custom sorting function then link this function to column definition.



           $scope.sortFun=function(a, b) { 
          ///.... your logic
          }

          _starRatingColumn = {
          name: 'starRating',
          cellTemplate: _starRatingTemplate,
          displayName: 'Rating',
          enableFiltering: false,
          enableSorting: true,
          cellClass: 'star-column',
          enableHiding: false,
          enableRowSelection: true,
          'sortingAlgorithm': $scope.sortFun
          }


          change your template.



          '<div class="ui-grid-cell-contents ">',
          '<div class="opr-star-rating" ng-class="col.colIndex() >',
          '<opr-star-rating rating-percentage="{{row.entity}}"',
          'total-count="23"',
          'suffix-display="true"',
          'rating-display="true"',
          'count-display="22">',
          '</opr-star-rating>',
          '</div>',
          '</div>'





          share|improve this answer















          You can define your custom sorting function then link this function to column definition.



           $scope.sortFun=function(a, b) { 
          ///.... your logic
          }

          _starRatingColumn = {
          name: 'starRating',
          cellTemplate: _starRatingTemplate,
          displayName: 'Rating',
          enableFiltering: false,
          enableSorting: true,
          cellClass: 'star-column',
          enableHiding: false,
          enableRowSelection: true,
          'sortingAlgorithm': $scope.sortFun
          }


          change your template.



          '<div class="ui-grid-cell-contents ">',
          '<div class="opr-star-rating" ng-class="col.colIndex() >',
          '<opr-star-rating rating-percentage="{{row.entity}}"',
          'total-count="23"',
          'suffix-display="true"',
          'rating-display="true"',
          'count-display="22">',
          '</opr-star-rating>',
          '</div>',
          '</div>'






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 '18 at 6:03

























          answered Nov 20 '18 at 4:55









          SameerSameer

          316210




          316210













          • actually, what I am not able to understand is, how to get the value of ratingPercentage in sorting function?

            – Anubha Gupta
            Nov 20 '18 at 5:06











          • change cell template according to this.

            – Sameer
            Nov 20 '18 at 5:33











          • It is not recognizing col property itself

            – Anubha Gupta
            Nov 20 '18 at 6:02











          • you can also use row.entity. you rating-percentage attribute will receive complete object of array result

            – Sameer
            Nov 20 '18 at 6:04













          • Yes I am trying with row.entity only. Problem is that it is not getting any of attribute mentioned in cellTemplate in row.entity. I am trying to get rating-percentage in row.entity. But no luck!

            – Anubha Gupta
            Nov 20 '18 at 6:06



















          • actually, what I am not able to understand is, how to get the value of ratingPercentage in sorting function?

            – Anubha Gupta
            Nov 20 '18 at 5:06











          • change cell template according to this.

            – Sameer
            Nov 20 '18 at 5:33











          • It is not recognizing col property itself

            – Anubha Gupta
            Nov 20 '18 at 6:02











          • you can also use row.entity. you rating-percentage attribute will receive complete object of array result

            – Sameer
            Nov 20 '18 at 6:04













          • Yes I am trying with row.entity only. Problem is that it is not getting any of attribute mentioned in cellTemplate in row.entity. I am trying to get rating-percentage in row.entity. But no luck!

            – Anubha Gupta
            Nov 20 '18 at 6:06

















          actually, what I am not able to understand is, how to get the value of ratingPercentage in sorting function?

          – Anubha Gupta
          Nov 20 '18 at 5:06





          actually, what I am not able to understand is, how to get the value of ratingPercentage in sorting function?

          – Anubha Gupta
          Nov 20 '18 at 5:06













          change cell template according to this.

          – Sameer
          Nov 20 '18 at 5:33





          change cell template according to this.

          – Sameer
          Nov 20 '18 at 5:33













          It is not recognizing col property itself

          – Anubha Gupta
          Nov 20 '18 at 6:02





          It is not recognizing col property itself

          – Anubha Gupta
          Nov 20 '18 at 6:02













          you can also use row.entity. you rating-percentage attribute will receive complete object of array result

          – Sameer
          Nov 20 '18 at 6:04







          you can also use row.entity. you rating-percentage attribute will receive complete object of array result

          – Sameer
          Nov 20 '18 at 6:04















          Yes I am trying with row.entity only. Problem is that it is not getting any of attribute mentioned in cellTemplate in row.entity. I am trying to get rating-percentage in row.entity. But no luck!

          – Anubha Gupta
          Nov 20 '18 at 6:06





          Yes I am trying with row.entity only. Problem is that it is not getting any of attribute mentioned in cellTemplate in row.entity. I am trying to get rating-percentage in row.entity. But no luck!

          – Anubha Gupta
          Nov 20 '18 at 6:06


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386381%2fhow-to-apply-sorting-in-ui-grid%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?