DevExpress ASPxGridView CommandColumn Built-in and Custom Button Sort Order Solution

DevExpress provides a number of useful controls that I've used for a variety of projects. I recently encountered an annoyance with the ASPxGridView controls Command Column. The Command Column provides a fixed set of out of the box buttons (Edit, New, Delete, Select) and the ability to specify custom buttons.

In my example below I am using the built-in Delete button, displayed first, and four custom buttons, one of which, displayed second, triggers navigation to a custom editor page. There isn't a way to change this ordering due to DevExpresses implementation of the command column ordering.

Buttons are rendered in the fixed order (Edit, New, Delete, Select, [Custom]) within DevExpress's code, GridViewTableCommandCell.CreateControlHierarchy(). This is fine if you use all of the built-in features of the DevExpress control however if you were to provide a custom button(s) as I have, it's not possible server side to force a custom button to be displayed before or intermingled with a built-in button.

The solution is to handle this client side with a jQuery function. There are many possible ways to go about sorting the command column but I wanted to just ensure that if the default delete button was used it would always display last in the command column.

$('td.dxgvCommandColumn').each(function() {
    var buttons = $(this).find('img.dxgvCommandColumnItem');
    
    if (buttons.length > 0) {
        var lastItem = buttons.last();
        $(this).find('img.dxgvCommandColumnItem[title=Remove]').insertAfter(lastItem);
    }
});

The command column is rendered for each row in the grid within a table cell with the class "dxgvCommandColumn". This script iterates over each of the command cells in the grid and finds the last button in the default rendered order. Command buttons are rendered as img tags with the class "dxgvCommandColumnItem". It then finds the delete command button using the title within the selector and moves it to after what was the last button. The end result looks like this:

Happy Coding!!

Author’s Note: This article reflects my personal professional experience and opinions. While my insights are informed by my professional history, these views are my own and do not represent the official position of my former employer.

About the Author: Jacob Marks is an engineering leader with over 20 years of experience, including a decade at Amazon Web Services (AWS) where he led teams in EC2 Core Platform and the development of the AWS Payment Cryptography service.

Labels

.NET .NET 10 .NET 3.5 Active Directory AD DS Adoption AI AI coding AI Ethics AI Hype Alerts Amazon Cognito Amazon DLM Amazon Q Anthropic AppDomain Architecture Artificial Intelligence Asia Pacific Sydney ASP.net ASPxGridView Audit Readiness Auto Recovery Automation AWS AWS Certified AWS Lambda AWS Payment Cryptography AWS SDK AWS Security Specialty Azure Azure DevOps Server Backup BIG-IP C# Career Growth Cartes Bancaires CB Certificate Bundle Certification Claude Cloud Cloud Certification Cloud Hosting Cloud Security CloudWatch CLR Content Query Cost Optimization Credentials CyberChef Database Defense Industry Deloitte Developer Tools Developers DevEx DevExpress DevOps DISA Disk Space DISM Distributed Systems DoD DoD CC SRG DUKPT EBS EC2 Engineering Engineering Leadership Engineering Management EnPasFltV2 Enterprise Event Receiver Exam F5 Federal IT FedRAMP Fintech FISMA GAC Generative AI GitHub gMSA GovCloud Government Compliance GridView Hardware Security Modules HSM IAM Identity Management IIS Infra Infrastructure as Code IT Tools Jacob Marks JavaScript jQuery Lambda Leadership Linqpad LLM lsass.exe LTM Memory Optimization Mentorship Microsoft Migration Multi-Region Keys NACL Native AOT Network Architecture Networking NIST ODBC Open Source Payment Cryptography Payments PCI Compliance Performance Platform Platform Architecture Power Tools PowerShell Python re:Invent Reachability Analyzer Redshift Relationships List Replace Root Volume SAA-C00 SAP-C00 Security Security Group Serverless SES SharePoint SharePoint 2010 Site Reliability SMTP Snapshot Software Engineering Solutions Architect Solutions Architect Professional SP 2007 SPAWAR SSL STIG Storage Strategy Sydney SysAdmin Team Foundation Server Team Utilities Tech Industry Technical Depth Technology TFS Tools Troubleshooting Upgrade Visual Studio VPC VPC Flow Logs Web Development WebPart WinDirStat Windows Server Windows Server 2025 WinForms