Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
285 views
in Technique[技术] by (71.8m points)

java - How to get Total Count and Filtered Count while implementing pagination

I'm trying to create an API implementing pagination. Now to call the API in the frontend I need the count of total records and filter records.

Here is the code to my repository:

public interface AssembelyRepository extends PagingAndSortingRepository<HardwareRegister, Long>{
    @Query
    ("select column from table h where condition")
    List<Object[]> getAssemblyData(@Param("ParameterA") String ParameterA,@Param("ParameterB") String ParameterA,Pageable pageable);
    
}

In the service layer, I'm converting the response to JSON object and calling the service class in my controller layer.

Here is my code for the controller layer:

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping(value="hardware")
public class AssemblyController {
    @Autowired
    private AssemblyService assemblyService;
    public String result="";
    @CrossOrigin("*")
    @GetMapping(value="/assembly",produces={MediaType.APPLICATION_JSON_VALUE})
    public String getAssemblyData(String ParameterA, String ParameterB,Pageable pageable) {
        return assemblyService.getAssemblyData(ParameterA,ParameterB,pageable);
    }
}

Now to implement this in the frontend I'm using- How to implement pagination with serverside get api in Datatables as an example, but here it is mentioned In the below format note the properties "TotalRecords", "RecordsFiltered". These are needed for datatable to recalculate pagination stuff and display proper number of pages.

Now I'm stuck as to how to display TotalRecords and RecordsFiltered.

question from:https://stackoverflow.com/questions/66058604/how-to-get-total-count-and-filtered-count-while-implementing-pagination

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...