fix: ordenacao numerica natural para marca de pecas (1, 2, 3... 10 em vez de alfabetica)
This commit is contained in:
@@ -157,11 +157,11 @@ export const SeletorItensOtimizado: React.FC<SeletorItensOtimizadoProps> = ({
|
|||||||
peca.marca.toLowerCase().includes(filtroNumeroPeca.toLowerCase())
|
peca.marca.toLowerCase().includes(filtroNumeroPeca.toLowerCase())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return pecasFiltradas.sort((a, b) => a.marca.localeCompare(b.marca));
|
return pecasFiltradas.sort((a, b) => a.marca.localeCompare(b.marca, undefined, { numeric: true, sensitivity: 'base' }));
|
||||||
}, [pecasDisponiveis, filtroNumeroPeca]);
|
}, [pecasDisponiveis, filtroNumeroPeca]);
|
||||||
|
|
||||||
const componentesOrdenados = useMemo(() => {
|
const componentesOrdenados = useMemo(() => {
|
||||||
return componentesDisponiveis.sort((a, b) => a.marca.localeCompare(b.marca));
|
return componentesDisponiveis.sort((a, b) => a.marca.localeCompare(b.marca, undefined, { numeric: true, sensitivity: 'base' }));
|
||||||
}, [componentesDisponiveis]);
|
}, [componentesDisponiveis]);
|
||||||
|
|
||||||
const fetchPecas = useCallback(async (term: string) => {
|
const fetchPecas = useCallback(async (term: string) => {
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ export const ItensRomaneioModal: React.FC<ItensRomaneioModalProps> = ({
|
|||||||
return parseInt(aNum[0]) - parseInt(bNum[0]);
|
return parseInt(aNum[0]) - parseInt(bNum[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return a.marca.localeCompare(b.marca);
|
return a.marca.localeCompare(b.marca, undefined, { numeric: true, sensitivity: 'base' });
|
||||||
});
|
});
|
||||||
}, [pecasDisponiveis, faseFilter, marcaFilter]);
|
}, [pecasDisponiveis, faseFilter, marcaFilter]);
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ export const RomaneioReportModal: React.FC<RomaneioReportModalProps> = ({
|
|||||||
if (typeof marcaA === 'number' && typeof marcaB === 'number') {
|
if (typeof marcaA === 'number' && typeof marcaB === 'number') {
|
||||||
return marcaA - marcaB;
|
return marcaA - marcaB;
|
||||||
}
|
}
|
||||||
return String(marcaA).localeCompare(String(marcaB));
|
return String(marcaA).localeCompare(String(marcaB), undefined, { numeric: true, sensitivity: 'base' });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -120,13 +120,18 @@ export const usePecasTable = (pecas: Peca[]) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
||||||
const comparison = aValue.localeCompare(bValue);
|
const comparison = aValue.localeCompare(bValue, undefined, { numeric: true, sensitivity: 'base' });
|
||||||
return sortOrder === 'asc' ? comparison : -comparison;
|
return sortOrder === 'asc' ? comparison : -comparison;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
||||||
return sortOrder === 'asc' ? aValue - bValue : bValue - aValue;
|
return sortOrder === 'asc' ? aValue - bValue : bValue - aValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (aValue != null && bValue != null) {
|
||||||
|
const comparison = String(aValue).localeCompare(String(bValue), undefined, { numeric: true, sensitivity: 'base' });
|
||||||
|
return sortOrder === 'asc' ? comparison : -comparison;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user