spring angular pagination problem sorting outputed data

i have a spring boot angular application already implemented ,i’m trying to implement a pagination within the project ,eveyrthing works fine except the fact that the data fetched to client side is not sorted properly ,for example i find data starts with id number 10 ,11 .. then unexpectedly jumps to id number 15 ,i also find id number 1 in page number 5 and so on ..

you can find images below illustrating my problem (sorry for deleting the rows ,it’s confidential plus we only have interest in the id column)

problem 2 : let’s say i updated the record of id =10, after saving the updates ,the record with id 10 dissapears from page 1 and get displayed in page 4 (for example)

i really can’t find a solution to this strange behavior

you can find also the project’s code : spring boot :

Repository:

public interface ServiceTypeRepository extends JpaRepository<ServiceType, Long>

    Page<ServiceType> findAll(Pageable pageable);
}

Service:

public Page<ServiceType> getServiceTypes(Pageable pageable) {
        return ServiceTypeRepository.findAll(pageable);

Resource(controller):

@ApiResponse(responseCode = "401", description = "Unauthorized")
    @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    @PreAuthorize(AccessRightConstants.SERVICETYPE_READ_PERMISSION)
    public ResponseEntity<List<ServiceTypeV2DTO>> get(Pageable pageable) { //  @RequestParam(defaultValue = "1") int page @RequestParam(defaultValue = "10") int size
        log.debug("REST request to get service types");
        // Pageable paging = PageRequest.of(page, size);
        Page<ServiceType> serviceTypes = ServiceTypeServiceV2.getServiceTypes(pageable);

        List<ServiceTypeV2DTO> serviceTypeV2DTOS = serviceTypes.stream()
                .sorted(Comparator.comparingInt(ServiceType::getNumericId))
                .map(DtoFactory::createServiceTypeV2DTO)
                .toList();

        return ResponseEntity.ok(serviceTypeV2DTOS);

angular app : (angular 17) :

Service methods :

 GetAll(params): Observable<any[]>{
        return this.httpClient.get<any[]>(`${this.SERVICE_TYPE_CONTEXT}`,{params});
    }

Update(ServiceDtoToSave : any): Observable<ServiceType>{
    let servTypeServiceDtoToSave: ServiceType = this.mapObjectToSave(ServiceDtoToSave);
        return this.httpClient.put<ServiceType>(`${(this.SERVICE_TYPE_CONTEXT)}` , servTypeServiceDtoToSave);
}

mapObjectToSave(serviceTypeDto: any): ServiceType{
        let ServiceDtoToSave : ServiceType = new ServiceType();
        serviceTypeDto.value? ServiceDtoToSave.value = serviceTypeDto.value:null;
        ServiceDtoToSave.name = serviceTypeDto.name;
        ServiceDtoToSave.minF = serviceTypeDto.minFwVersion;
         ServiceDtoToSave.compat = serviceTypeDto.compat;
        ServiceDtoToSave.compat2 = serviceTypeDto.compat2;
        ServiceDtoToSave.compat3 = serviceTypeDto.compat3;
        ServiceDtoToSave.compat4= serviceTypeDto.compat4;
        ServiceDtoToSave.attributesService = [];
        ServiceDtoToSave?.attributesService.forEach(attribute=> {
            ServiceDtoToSave.attributesService.push({
                name : attribute.name,
                value : attribute.value
            })});

        return ServiceDtoToSave;
    }


component.ts:



//declaration

   page: number = 1;
    pageSize: number = 26;
    name = '';



   totalItems: number = 256;

    serviceTypeForm: FormGroup
    editmode = false;
    serviceType: ServiceType [];
    selectedService: ServiceType; 

//methods

 loadServicesV2(){
        const params = this.getRequestParams(this.page, this.pageSize);
    this.serviceTypeV2.GetAll(params)
        .subscribe({
            next: (result: ServiceType[]) => {

               this.serviceType = result;
                this.serviceType = result.sort((a, b) => a.value - b.value);
                console.log(result);


             // this.totalItems = parseInt(result.headers.get('x-total-count'));
            },
            error: (e) => console.error(e)
        });


}

    editSaveServices() {
        this.editServiceType();
        this.formToSelectedService();

        this.serviceTypeService.update(this.selectedService, (result: ServiceType[]) => {

            this.loadServicesV2();

        })
}

  changePage($event) {
        this.page = $event;
        this.loadServicesV2();
    }

html:

 <div class="d-flex justify-content-center">
                        <ngb-pagination (pageChange)="changePage($event)" [(page)]="page" [boundaryLinks]="true"
                                        [collectionSize]="totalItems"  [ellipses]="true" [maxSize]="10"
                                        [pageSize]=pageSize></ngb-pagination>
                    </div>


enter image description here
enter image description here

this.serviceType = result.sort((a, b) => a.value – b.value);

notice that i tried to sort data by id in order to solve the error but the list still starts with id 10, you can find id number 1 in page 4 (see second image)

sorry once again for the lack of resources, i hope that i provided the code in an understandable way

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật