Hi Sugu Maran,
Greetings from Syncfusion Support.
We have
reviewed your requirement about sorting the records numeric and non-numericYou
can achieve similar sorting functionality by splitting the numeric and
non-numeric parts of the reference and comparer using regular expressions and
comparing them appropriately. We have prepared a code snippet that resembles
Natural Sort using the sortComparer function, which you can find below:
|
function sortComparer(reference, comparer) {
var referenceParts = [],
comparerParts = [];
reference.replace(/(\d+)|(\D+)/g, function (_, $1, $2) {
referenceParts.push([$1 || Infinity, $2 || '']);
});
comparer.replace(/(\d+)|(\D+)/g, function (_, $1, $2) {
comparerParts.push([$1 || Infinity, $2 || '']);
});
while (referenceParts.length && comparerParts.length) {
var referencePart = referenceParts.shift();
var comparerPart = comparerParts.shift();
var comparisonResult =
referencePart[0] - comparerPart[0] ||
referencePart[1].localeCompare(comparerPart[1]);
if (comparisonResult) return comparisonResult;
}
return referenceParts.length - comparerParts.length;
}
|
Using
the above logic, you can sort the values in the columns in Natural Order. We
have modified the sample you provided with the code snippet above. You can find
the modified sample attached below.
Sample: https://stackblitz.com/edit/cjg4fs-qnug1z?file=index.ts
Documentation: https://ej2.syncfusion.com/javascript/documentation/grid/sorting#custom-sort-comparer
Please let us know if you need any further assistance.
Regards,
Dineshnarasimman M