Setting alphabetical order on Knowledge Feature Articles widget

User175049
Mega Guru

Hello,

I have a request to set the Featured Articles widget to order alphabetically.  So far this is the HTML I updated. 

<div class="kb-article-list">
<sp-widget widget="::c.data.template"></sp-widget>
<div role="listitem" ng-repeat="kb_article in data.items| orderBy :'+short_description'" class="sp-kb-topic-article m-b-lg">
</div>

 

This somewhat works. Unfortunately, it is ordering the articles Z-A instead of A-Z.  I made sure the orderBy parameter prefix is  +  , though it's not ordering in that direction. What am I missing on this HTML ?  Or is there a better way to achieve this goal?  I also noticed that one article is missing with this update, but that could be another issue.

Thank you for any input.

~m

1 REPLY 1

Marco0o1
Tera Sage

Hi @User175049 ,

The iz way to resolve your problem is sort the data when you are requesting the data in the Server Script, something like this:

 //You request of data
var GR = newGlideRecord('kb_article'); //Your table
GR.addQuery("Some queryies you add") // There s you n queries quatity
GR.orderBy('short_description'); // Your field with the titles if you want to reverse order use // GR.orderByDesc('name');
GR.orderBy('short_description'); // You can add a second sort
GR.query();
// Then your logic and the form you add the data and save to express.

 

Another way you can do is order you data in the client script, just add this:

 

c.data.items.sort((a, b) => a.short_description.localeCompare(b.short_description));

Then just delete  orderBy :'+short_description' you have when you declare your ng-repeat

Hope that help you.