is there a way to disable the default header click sorting feature for a grid control in a dialog ?
Not aware of what you have stated. Checked this on a dialog in base and one in Calc - neither does anything with clicking on grid control anywhere. I do have a grid control with mouse handler to perform something else on a click. This is the only option I an aware of - adding code to do this.
Can you provide a sample?
Gridder.ods (11.4 KB)
ok here it is.
push button on the sheet opens the Dialog with Grid control in it
now when u click any of the column headers of the Grid it sorts the table by default
i wanted to know if this can be avoided
im using libre 184.108.40.206
also the only reason i dont want that sorting is that if any row is already selected when a header is clicked, then the sort happens and the selected row changes too by default - but if the event listener “Selection Changed” is added, thats not triggered.
this will be a problem since i got other things to do based on the selected row the moment the selection changes.
i mean instantly on any change.
so - for any such grid the selected row can possibly change by default either with the up down arrow keys OR the column header clicks OR a normal mouse click on the row.
so the only way to keep it clean and simple and avoid some messy coding is to just turn off that auto sorting. any other user action that changes the selected row will always trigger the Change listener but the auto sort will not so it has to be stopped
Well so far I am not certain where your issue is. Will continue investigation it.
Have two alternatives in the meantime. These are both items I have used previously.
Alternative works (may not in v220.127.116.11) but column 1 width is off. Haven’t found the problem.
Alternative 2 works fine.
Thought I’d give you something to view.
Gridder.ods (15.2 KB)
Also added two lines to your routine. You weren’t loading the library and it crashed when first opening.
Can also be done in Python:
How to use a gridcontrol in a dialog, as kind of multicolumn listbox
and response to that:
so in short the fix in my case was to just add the “DefaultGridDataModel”
that 1 doesnt do the auto sort thing
@Ratslinger. Thanks for the sortable column option. In the end is comes down to
oDataModel1 = createUnoService("com.sun.star.awt.grid.DefaultGridDataModel") 'not sortable oDataModel2 = oGridModel.GridDataModel ' sortable
oDataModel2 supports the com.sun.star.awt.grid.SortableGridDataModel, in my case this service leads to a crash when called directly as a createUnoService.
With this thread as incentive I updated/adapted/upgraded the sample file in the ‘how to use a …’ thread. The sortable columns are present, and with an extra numeric field sorting is done while maintaining the already selected rows.
1: to cut off uncovered bypasses the columnheaders had to be switched off
2: in my case the embedded dialogs give a very wide first and second column, the rest is cramped to the right. (The same behaviour with the gridder file here.)
3: because columnheaders are disabled, there is no option to adjust the width by hand
Some special care was required for correct sorting, in basic forcing columns to integer, with python no precautions had to be taken, using a mix of integer and string.
I use linuxmint 20.1, LO 18.104.22.168
That was @bloke - was asked to remove.