Open ColumnMenu on column header click instead of sort

Hello,

is it possible top open the ColumnMenu when clicking the ColumnHeader and do not sort, but allow sorting only via ColumnMenu?

Kind regards

Kevin


3 Replies 1 reply marked as answer

PS Prathap Senthil Syncfusion Team April 9, 2025 02:29 PM UTC

Hi Kevin Hoffmann,


Yes, it is possible to disable sorting when clicking on the header text using a JavaScript solution, while still allowing the column menu to function as normal. Kindly refer to the code snippet and sample below for your reference.


     protected override async Task OnAfterRenderAsync(bool firstRender)

    {

        if (firstRender)

        {

            await RunTime.InvokeVoidAsync("disableSortingExceptColumnMenu", "MyGrid");

        }

    }

 

JavaScript.js


function disableSortingExceptColumnMenu(gridId) {

    const grid = document.getElementById(gridId);

    if (!grid) return;

 

    const headers = grid.querySelectorAll('.e-headercell');

 

    headers.forEach(header => {

        header.addEventListener('click', function (e) {

            const isColumnMenuClick = e.target.closest('.e-columnmenu');

 

            if (!isColumnMenuClick) {

                // Prevent sorting

                e.stopPropagation();

                e.preventDefault();

            }

        }, true);

    });

};

 

 

 


Regards,
Prathap Senthil


Attachment: DataGrid_7aa569cb.zip

Marked as answer

KH Kevin Hoffmann April 10, 2025 08:20 AM UTC

Thanks for the quick reply. Your solution does exactly what I wanted.



NP Naveen Palanivel Syncfusion Team April 11, 2025 10:36 AM UTC

Hi Kevin ,


We are glad to hear that the provided response was helpful.  If you have any further questions or need assistance in the future, feel free to reach out. We're always happy to help!


Best regards,
Naveen


Loader.
Up arrow icon