Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default sort behavior #104

Closed
BoboITCov opened this issue Feb 16, 2015 · 6 comments
Closed

Default sort behavior #104

BoboITCov opened this issue Feb 16, 2015 · 6 comments
Labels

Comments

@BoboITCov
Copy link

Hi rstaib,
basically I want to be able to control which column should be used for sorting by default.
I've tried using http://www.jquery-bootgrid.com/Documentation#methods > sort, but don't seem to be able to make it work?
Any hint will be appreciated?

Cheers!

@shadeven
Copy link

@BoboITCov,
By default, each column is sortable. You can make it unsortable by adding data-sortable="false" in the table header. Please refer to the selection example: http://www.jquery-bootgrid.com/Examples

@BoboITCov
Copy link
Author

Hi Shadevan,
thank you for the quick reply, but that is not the question here... :)
The way I use the plug-in is:

  1. generate the data from DB to HTML. There are about 400 records, nothing special.

    1.1. the records are sorted by column 2 (creation date) DESC

  2. init bootgrid (the basic usage example with on "loaded" method extras: commands, etc.)

    2.1. now the records are sorted by column 1 (name) and I have to

    2.2. click on column 2 until they are again sorted by creation date DESC

So the question is:
Is there a way to force the data to be sorted by column N asc/desc on bootgrid init
OR
Is there a way to force the data to be sorted by column N asc/desc with on "loaded" method?

@shadeven
Copy link

@BoboITCov,

I guess the "sort" Method could be the way to go although I haven't tried it myself.
On "loaded" event, you can invoke the "sort" method by $("#grid").bootgrid("sort", PlainObject);
You need to define the PlainObject as a dictionary where you can choose the column to be sorted in ascending or descending order.

Unfortunately the website does not provide such example. Good luck!

@shadeven
Copy link

@BoboITCov,
I just discovered that we can sort data by column on init. Simply add "data-order" in the table header. The default value is "", you can set it to "asc" or "desc".

Please see the code snippet below:

ID

@rstaib rstaib added the question label Mar 6, 2015
@rstaib
Copy link
Owner

rstaib commented Mar 6, 2015

@shadeven Thanks for answering the question!

@BoboITCov Here you find all existing column settings which will have an impact on initialization.

@rstaib rstaib closed this as completed Mar 6, 2015
@ShemoMFR
Copy link

ShemoMFR commented Nov 3, 2022

Hi ! I got a problem with sorting column of bootgrid : I cant sort any column of my table. I tried data-order, data-sortable, etc... its not working. I have other table built with bootgrid and they are working fine.

Other strange behavior : the first time I am loading the table, I can sort once and after its not working.

If someone has an idea...

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants