Skip to content

Commit 100a876

Browse files
committed
#205 - Sort order fix in TermPicker
1 parent 194adda commit 100a876

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

src/controls/taxonomyPicker/TermParent.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ export default class TermParent extends React.Component<ITermParentProps, ITermP
3131
/**
3232
* componentWillMount
3333
*/
34-
public componentWillMount()
35-
{
34+
public componentWillMount() {
3635
// fix term depth if anchroid for rendering
3736
if (this.props.anchorId)
3837
{
3938
const anchorTerm = this._terms.filter(t => t.Id.toLowerCase() === this.props.anchorId.toLowerCase()).shift();
40-
if (anchorTerm)
41-
{
39+
if (anchorTerm) {
4240
const anchorDepth = anchorTerm.PathDepth;
4341
this._anchorName = anchorTerm.Name;
4442
var anchorTerms : ITerm[] = this._terms.filter(t => t.PathOfTerm.substring(0, anchorTerm.PathOfTerm.length) === anchorTerm.PathOfTerm && t.Id !== anchorTerm.Id);

src/services/SPTermStorePickerService.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class SPTermStorePickerService {
5757
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then((serviceResponse: SPHttpClientResponse) => {
5858
return serviceResponse.json().then((serviceJSONResponse: any) => {
5959
// Construct results
60-
let termStoreResult: ITermStore[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermStore');
60+
let termStoreResult: ITermStore[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermStore');
6161
// Check if term store was retrieved
6262
if (termStoreResult.length > 0) {
6363
// Check if the termstore needs to be filtered or limited
@@ -146,13 +146,13 @@ export default class SPTermStorePickerService {
146146

147147
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then((serviceResponse: SPHttpClientResponse) => {
148148
return serviceResponse.json().then((serviceJSONResponse: any) => {
149-
const termStoreResultTermSets: ITermSet[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermSet');
149+
const termStoreResultTermSets: ITermSet[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermSet');
150150

151151
if (termStoreResultTermSets.length > 0) {
152152
var termStoreResultTermSet = termStoreResultTermSets[0];
153153
termStoreResultTermSet.Terms = [];
154154
// Retrieve the term collection results
155-
const termStoreResultTerms: ITerms[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
155+
const termStoreResultTerms: ITerms[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
156156
if (termStoreResultTerms.length > 0) {
157157
// Retrieve all terms
158158
let terms = termStoreResultTerms[0]._Child_Items_;
@@ -264,7 +264,7 @@ export default class SPTermStorePickerService {
264264
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then((serviceResponse: SPHttpClientResponse) => {
265265
return serviceResponse.json().then((serviceJSONResponse: any) => {
266266
// Retrieve the term collection results
267-
const termStoreResult: ITerms[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
267+
const termStoreResult: ITerms[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
268268
if (termStoreResult.length > 0) {
269269
// Retrieve all terms
270270

@@ -302,15 +302,15 @@ export default class SPTermStorePickerService {
302302
* @param b term 2
303303
*/
304304
private _sortTerms(a: ITerm, b: ITerm) {
305-
if(a.CustomSortOrderIndex === -1){
306-
if (a.PathOfTerm < b.PathOfTerm) {
305+
if (a.CustomSortOrderIndex === -1) {
306+
if (a.PathOfTerm.toLowerCase() < b.PathOfTerm.toLowerCase()) {
307307
return -1;
308308
}
309-
if (a.PathOfTerm > b.PathOfTerm) {
309+
if (a.PathOfTerm.toLowerCase() > b.PathOfTerm.toLowerCase()) {
310310
return 1;
311311
}
312312
return 0;
313-
}else{
313+
} else {
314314
if (a.CustomSortOrderIndex < b.CustomSortOrderIndex) {
315315
return -1;
316316
}
@@ -319,7 +319,6 @@ export default class SPTermStorePickerService {
319319
}
320320
return 0;
321321
}
322-
323322
}
324323

325324
/**

0 commit comments

Comments
 (0)