Question

Using backgrid, displaying users list. 'User' model having first_name and last_name attributes. I have wrote method full_name on user model and displaying that full name into backgrid.

{
  name: "full_name",
  label: "Name",
  editable: false,
  cell: 'string'
}

On server side using will_pagination. When I clicks on full_name to sort. It gives error - "ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column "full_name" does not exist".

So I need to sort on first_name instead of full_name. But I don't know how to do? Any suggestions?

Was it helpful?

Solution 2

On server side, this can be handled by overriding the param 'sort_by' value and order. We can pass multiple columns in order. In this case instead of 'full_name', applied order on first_name and last_name. For example:

User.paginate(page: params[:current_page], per_page: params[:pageSize]).order("first_name asc, last_name asc")

OTHER TIPS

You are sorting with full_name make it sortable with first_name. Don't use full_name in your will_paginate and backgrid configurations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top