how to apply sorting in ui-grid?
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
add a comment |
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
add a comment |
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
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
angularjs angular-ui-grid ui-grid
asked Nov 20 '18 at 4:44
Anubha GuptaAnubha Gupta
469
469
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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>'
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
|
show 1 more comment
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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>'
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
|
show 1 more comment
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>'
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
|
show 1 more comment
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>'
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>'
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
|
show 1 more comment
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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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