@jianmei.fan, while we support a few different ways of string sorting out-of-the-box (such as alphanumerical or natural), the kind of sorting you want appears quite specific, so indeed custom comparison functions is the way to go. Here is the post that explains how to use them: JavaScript API updates
I also went ahead and created a script for your particular use case:
// Providing custom comparer function
let column = DG.Column.fromList(DG.TYPE.STRING, 'id',
['BA123456', 'NNN-ABC123', 'CA-101010', 'CA-101020']);
column.valueComparer = (s1, s2) => {
let c1 = s1.startsWith('CA');
let c2 = s2.startsWith('CA');
if (c1 && c2 || !c1 && !c2) return s1.localeCompare(s2);
return c1 ? 1 : -1;
}
// in case you need the order. prints BA123456, NNN-ABC123, CA-101010, CA-101020
let order = column.getSortedOrder();
grok.shell.info(Array.from(order).map((i) => column.get(i)).join(', '));
// double-click on the header to sort
grok.shell.addTableView(DG.DataFrame.fromColumns([column]));