Base solution for your next web application
Open Closed

Datatable RowAction hidden with one button #10464


User avatar
0
williepieterse created

Prerequisites

10.2, MVC, .net core

When you only have one action button in row actions the Actions column is hidden automaticaly and the 2nd column only have data in the first row:

One Button:

{
                width: 'auto',
                targets: 1,
                data: null,
                orderable: false,
                autoWidth: true,
                defaultContent: '',
                rowAction: {
                    cssClass: 'btn btn-brand dropdown-toggle',
                    text: '<i class="fa fa-cog"></i><span class="hidden-phone"> ' + app.localize('Actions') + '</span><span class="caret"></span>',
                    items: [{
                        text: app.localize('View'),
                        iconStyle: 'far fa-eye mr-2',
                        action: function (data) {
                            _viewEmployeeTransactionModal.open({
                                id: data.record.employeeTransaction.id
                            });
                        }
                    }]
                }
            },

Result:

**Invisible 2nd button to force it to work: **

{
                width: 'auto',
                targets: 1,
                data: null,
                orderable: false,
                autoWidth: true,
                defaultContent: '',
                rowAction: {
                    cssClass: 'btn btn-brand dropdown-toggle',
                    text: '<i class="fa fa-cog"></i><span class="hidden-phone"> ' + app.localize('Actions') + '</span><span class="caret"></span>',
                    items: [{
                        text: app.localize('View'),
                        iconStyle: 'far fa-eye mr-2',
                        action: function (data) {
                            _viewEmployeeTransactionModal.open({
                                id: data.record.employeeTransaction.id
                            });
                        }
                    }
                    , {
                        visible: function () {
                            return false;
                        },
                        text: app.localize('View'),
                        iconStyle: 'far fa-eye mr-2',
                        action: function (data) {
                            _viewEmployeeTrackingModal.open({
                                id: data.record.employeeTracking.id
                            });
                        }
                    }
                    ]
                }
            },

Result


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you want to use 1 button in rowAction, you should define it as shown below;

    rowAction: {
        element: $('<button>' + app.localize('Select') + '</button>')
            .addClass("btn btn-primary")
            .attr("title", app.localize('Select'))
            .append($("").addClass("fa fa-chevron-circle-right")).click(function() {
                var record = $(this).data();
                alert(record.id);
            })
    }
    

    As I can see, this is not documented, we will update the documentation.

    Thanks,