Skip to content

Commit

Permalink
Feature/fix rating (#10)
Browse files Browse the repository at this point in the history
fix: Fix Numberic's sorting & accuracy logic
  • Loading branch information
ranglang committed Aug 3, 2023
1 parent daffbda commit 0ac3e53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.12",
"version": "1.1.15",
"description": "my apitable widget chart",
"engines": {
"node": ">=8.x"
Expand Down
13 changes: 12 additions & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export const formatDatetime = (cv: number | number[], format: string) => {
* @returns
*/
export const getNumberBaseFieldPrecision = (field?: Field) => {


let precision = 2;
if (!field) return precision;
// When there is precision in the property of the entity field itself.
Expand Down Expand Up @@ -195,8 +197,9 @@ export const getAggregationValue = (dataList: number[], type: string, precision
}
if (res != null) {
// console.warn('Non-numeric field summary error');
return isNumber(res) ? parseFloat(res.toFixed(precision)) : 0;
return isNumber(res) ? res.toFixed(precision) : 0;
}

return res;
};

Expand Down Expand Up @@ -579,6 +582,10 @@ export const getSortFuncByField = (key: string, field?: Field, isAxis = true) =>
case FieldType.MagicLookUp:
const referenceField = property.entityField.field;
return (item) => getReferenceSeriesValue([item[key]], referenceField);
case FieldType.Rating:
return (item) => {
return Number(item[key]);
};
default:
return (item) => {
const value = item[key];
Expand Down Expand Up @@ -607,6 +614,10 @@ export const getSortFuncByField = (key: string, field?: Field, isAxis = true) =>
return (item) => item[key];
case FieldType.AutoNumber:
return (item) => Number(item[key]);
case FieldType.Rating:
return (item) => {
return Number(item[key]);
};
case FieldType.MagicLookUp:
const referenceField = property.entityField.field;
return getSortFuncByField(key, referenceField);
Expand Down

0 comments on commit 0ac3e53

Please sign in to comment.