ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: tcf on January 29, 2016, 03:21:17 am

Title: Restrict the sorting to 2 columns only ?
Post by: tcf 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
Title: Re: Restrict the sorting to 2 columns only ?
Post by: paramvir 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
Title: Re: Restrict the sorting to 2 columns only ?
Post by: tcf 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.
Title: Re: Restrict the sorting to 2 columns only ?
Post by: paramvir 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;
}
},
Title: Re: Restrict the sorting to 2 columns only ?
Post by: tcf 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
Title: Re: Restrict the sorting to 2 columns only ?
Post by: paramvir 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.
}
},