Skip to content

Sorting Object not being created when using native query  #40

@undavalli

Description

@undavalli
   <th><a class="sorted"  sd:pagination-sort="DBColumnname">DBColumnname</a></th>

I am using above in my html page and I am trying to create a sort order dynamically and pass it to backend controller. In the backend I am using EntityManager to create a native query and assign result set to an object. Below is how my code looks

   @Component
    public class TestRepositoryImpl {

@Autowired
EntityManager em;

public Page<TestObject> getData(String fromDate, String toDate, String strNumber, Integer cardTypeNu,
		Pageable pageable) {
	String countClause = this.formatString("", fromDate, toDate, strNumber, cardTypeNu, pageable);
	String totolCountClause = this.formatString("", fromDate, toDate, strNumber, cardTypeNu);
	String str = " Select column names from DB and append to countClause " + countClause;
	String totalCountQuery = "Select count (*) from column names from DB and append to totolCountClause"
			+ totolCountClause + "  a ";
	Query query = em.createNativeQuery(str);
	Query countQuery = em.createNativeQuery(totalCountQuery);
	if (){
	setparameters if satisfies if conditions 
	}
	Pageable pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize());
	@SuppressWarnings("unchecked")
	List<Object[]> obj = query.setFirstResult((pageable.getPageNumber()) * (pageable.getPageSize()))
			.setMaxResults(pageable.getPageSize()).getResultList();

	int size = (int) countQuery.getResultList().get(0);
	return getCancelledGiftcardsPageInfo(this.mappingObjWithReceipt(obj), pageRequest, size);
}
/**
 * @param obj
 *            results from Query
 * @return testObject mapped list with Object
 */
public List<TestObject> mappingObjWithtestObject(List<Object[]> obj) {
	List<TestObject> testObject = new ArrayList<>();
	if (obj != null) {
		obj.forEach(obj1 -> {
			mapp to all setters
		});
	}
	return testObject;
}
    }

let me know If I am missing something.

Expectation:
I am expecting sd:pagination-sort to send field name and Sort type Ascending or Descending to controller, But it is sending only field name and not the Sort type value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions