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

Add 3-state (asc/desc/no) column sorting option #141

Closed
wants to merge 1 commit into from

Conversation

mcw0933
Copy link

@mcw0933 mcw0933 commented Sep 11, 2015

Create grid option, 'sortmode', for determining sort mode
Default setting to 2 for 2-state (asc->desc->asc) sorting
In sort handler, if 3, use 3-state (asc->desc->no->asc)

    Create grid option, 'sortmode', for determining sort mode
    Default setting to 2 for 2-state (asc->desc->asc) sorting
    In sort handler, if 3, use 3-state (asc->desc->no->asc)
@mcw0933
Copy link
Author

mcw0933 commented Sep 11, 2015

@OlegKi (and co), please take a look at this minor feature enhancement.

At my employer we are using a slightly modified version of jqGrid 4.5.4 - modified with some enhancements such as this. I actually submitted this as a pull request on jqGrid but I've never received any feedback on it (or my other ones). I asked Tony about it in a Github issue and got a lukewarm response. Seems he never got around to finishing that PR sweep.

Anyhow, we would love to migrate over to a fully standard version of free-jqgrid, if these features can be incorporated. Please take a look at this PR and provide any feedback you may have. Let me know if there are any contributor or project standards I should follow. Thank you!

@OlegKi
Copy link
Member

OlegKi commented Sep 12, 2015

Hi Matt! Thank you for pointing to the problem of 3-state sorting. I find the idea interesting, but I can't apply (merge) your pull request because of many reasons:

  1. the pull request contains modification of jquery.jqgrid.src.js file which will be automatically generated by merging of other modules of jqGrid. The origin of the code is inside of grid.base.js.
  2. one should clear formulate the description of the new feature first and the scope of usage. What should the feature do exactly? Only after that one could makes the corresponding modifications. One should additionally think about backward compatibility. One should take in consideration all different combinations of other related options. For example, jqGrid implement sorting locally or remotely, jqGrid support single column sorting and multi-column sorting. The implementation which you suggest do the following: it set sortorder to "" only. If one uses remote sorting then the current jqGrid implementation will still send request to the server with sord with empty value and with non-empty sidx. On the other side the setting of sortname to "" (and thus empty sidx) is the standard way in old versions of jqGrid to prevent sorting of grid. I suppose that the corresponding request to the server should contains empty sidx.

One more important problem. I tested the code which you suggested. It works not like I would intuitively expect from 3-state sorting. If one creates unsorted jqGrid then it displays no visible sorting icons in the column headers. The first clicking on the column header sorts the grid by the column based on firstsortorder property of the clicked column or "asc" if no firstsortorder property is defined. The next click inverts the previous state. It's the default behaving of existing jqGrid in case of no multisort are used (no multiSort: true option are set).

Now we can get back to your current suggestion. If one creates grid without any sortorder parameter or with sortorder: "asc" then jqGrid set sortorder: "desc" on the next click and set sortorder: "" after the next click. jqGrid still displays both sorting icons in case of unsorted grid (sortorder: ""). Both sorting icons are disabled/grayed, but there still be displayed. I find the behavior incorrect.

The next problem which I found is the following. Let us we create sorted grid with sortorder: "desc" (sortname is set to some column). After the first click clicking on the column will be unsorted and both sorting icons will be disabled/grayed. It's not what the user expect by default. I would expect inversion of sorting order on the first click and unsorted column only if the user clicks on the same column header one more time.

I would point your attention on one feature of jqGrid which already implemented. To see the feature you can add multiSort: true option to the grid. Try to click on the same column header (which is already sorted). The grid will invert the string order (even if sortorder: "desc" was used initially). The next click will make the grid unsorted and the sorting icons will be not visible. It's exactly the behavior which I would expect from 3-state sorting. The only problem is that the behavior is currently implemented in multi-sort mode only. If the user clicks on the next column then the grid will add one more sorting criteria and the previous sorting will be not removed. If I correctly understand your requirements you need to have 3-state sorting by one column. I full agree that it can have sense. I just think that your current suggestion don't correctly implement that requirement. I would glad if you analyse the code of multiSort and sortData methods more carefully and if you post another implementation of 3-state sorting behavior which work without multiSort: true option.

@OlegKi OlegKi closed this Sep 12, 2015
@OlegKi
Copy link
Member

OlegKi commented Sep 20, 2015

Hi Matt!

I didn't get any new post from you. So I looked in the code of jqGrid myself and created the preliminary modification of free jqGrid code, which implements 3-state sorting. The demo uses the modified code. It contains new boolean option threeStateSort: true (equivalent to sortmode: 3 which you used), which can be combined with the standard sorting (without multiSort: true which is always 3-state sorting). I wanted to optimize a little the code before publishing on GitHub, but the jquery.jqgrid.src.js used in the demo should already implements all like I understand the problem. It would be good if you could test the code and to post your opinion or your critic about the modifications.

Best regards
Oleg

@mcw0933
Copy link
Author

mcw0933 commented Sep 22, 2015

Hi Oleg,

Yes, the demo you linked to does implement 3-state sorting. It is slightly different than what we are doing presently.

In our case, we show both sorting arrows but with both in the "unselected" state. We do that because it suggests that the column is sortable, but not sorted, as opposed to a column which may not be sortable at all. It seems to me that the feature as implemented could be confusing to enable for a grid with some columns sortable and others not.

If you publish the feature as is, would it be possible for us to style the sorting arrows so they appear? Or does the new code remove them as elements from the markup?

Either way, I appreciate you taking this up. I would like to get more familiar with the free-jqGrid build process so that I might submit some other feature requests. Is there anywhere that you have a guide for contributors to get started?

@OlegKi
Copy link
Member

OlegKi commented Sep 22, 2015

Hi Matt,

i posted the current code to GitHub because I didn't found any bugs. Sorting feature of jqGrid contains now many options. For example there are sortIconsBeforeText:true option which can move the sorting icons before the text. The feature was implemented because on requirement to display the icons even for the long text in the column header. There are showOneSortIcon: true icon which can be used to hide disabled sorting icon. It can be helpful if one uses alternative sorting icons. There are old viewsortcols option, with default value [false, "vertical", true] (see old documentation). Setting of the first item of the array to true seems to be close to your requirements. It specify whether sorting icons should be visible (but disabled) for sortable columns.

Unsorted columns contains all sorting icons, but the outer div is hidden. The state in the third state is identical to the unsorted grid which one have if one uses no sortname parameter or sortname: "" parameter: no sorting icons will be displayed in any column of the grid.

By the way the cursor in the column header in free jqGrid shows whether the column is sortable or not. Try to move the cursor over non-sortable column "Notes" in the demo and compare it with the cursor in other columns. You will see what I mean.

I introduced additionally $.jgrid.builderSortIcons method which can be overwritten to implement more advanced scenarios for sorting icons. For example one can display one sorting icon for dates, another for texts and the third one for numbers. See here for example the corresponding icons.

I plan to create good new site with full documentation and the corresponding demos, but I still have some time problems. It's difficult to invest much time in the product which one provide for free. :-)

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

Successfully merging this pull request may close these issues.

2 participants