Author Topic: Restrict the sorting to 2 columns only ?  (Read 3124 times)

tcf

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 13
    • View Profile
Restrict the sorting to 2 columns only ?
« on: January 29, 2016, 03:21:17 am »
I need to only allow 2 columns to be sorted.

Is it possible to restrict the sorting to 2 columns only ?

Thanks

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Restrict the sorting to 2 columns only ?
« Reply #1 on: January 29, 2016, 09:01:25 am »
yes, there is a sortable property for a column.

http://paramquery.com/pro/api#option-column-sortable

tcf

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Restrict the sorting to 2 columns only ?
« Reply #2 on: January 29, 2016, 07:08:29 pm »
I don't think this answers my question...

All fields have been set to be sortable, but I want to restrict the user so he can only select 2 of those fields to be sorted.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Restrict the sorting to 2 columns only ?
« Reply #3 on: January 29, 2016, 07:45:33 pm »
if your question is in the context of multi column sorting and the requirement is to limit the user to sort at the most any 2 columns, then use beforeSort event.

http://paramquery.com/pro/api#event-beforeSort

count the length of ui.sorter array in the event and return false if length > 2

Code: [Select]
beforeSort: function(evt, ui){
if( ui.sorter.length > 2 ){
return false;
}
},
« Last Edit: January 29, 2016, 07:52:21 pm by paramquery »

tcf

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Restrict the sorting to 2 columns only ?
« Reply #4 on: January 29, 2016, 10:21:02 pm »
That works great... however what would be even better if the user clicked on a 3rd header to be sorted the 2nd header sorter was removed ?

i.e. say I had 3 columns Year, First Name, Second Name

The user clicks on Year and Year is sorted, then clicks on First Name and First Name is sorted within Year...

The user then clicks on Second Name which is the 3rd sort, so the sort on First Name is removed and the Second Name is sorted.

Hope that makes sense ?

Thanks

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Restrict the sorting to 2 columns only ?
« Reply #5 on: February 01, 2016, 09:23:44 am »
Please use this:

Code: [Select]
beforeSort: function(evt, ui){
if( ui.sorter.length > 2 ){
ui.sorter.splice( 1, 1); //remove the 2nd entry from ui.sorter array.
}
},
« Last Edit: February 01, 2016, 09:27:07 am by paramquery »