简体   繁体   English

如何通过另一列中的数据使 jQuery DataTable 列中的按钮可见?

[英]How to make visible a button in a jQuery DataTable column by data in another column?

I want to set the button in another column to be visible / hidden according to the status data in one column of the data table.我想根据数据表一列中的状态数据将另一列中的按钮设置为可见/隐藏。

I tried this:我试过这个:

{
                targets: 6,
                data: null,
                orderable: false,
                defaultContent: '',
                rowAction: {
                    element:
                            $("<button/>")
                            .addClass("btn btn-sm btn-danger")
                            .text(app.localize('SendToDepartments'))
                            .click(function () {
                                debugger;
                                var id = $(this).data().id;
                                _sendToDepartmentsModal.open({ id });
                            }),
                    visible: function () {
                        debugger;
                        var status = _$annotationDepartmentInboxFromManagerTable
                            .row()
                            .data().status;
                        
                        if (status != 'Sent To Departments') {
                            return true;
                        }
                        else {
                            return false;
                        }
                    }
                }
            },

But this changes the visibility of the buttons on all rows.但这会改变所有行上按钮的可见性。

How can I do it?我该怎么做?

It is solved, I used render:解决了,我用了渲染:

  render: function (data, type, full, meta) {                     
                        if (full.status != 'Sent To Departments') {
                            return '<button class="btn btn-sm btn-danger" data-name="' + full.id + '">' + "click!"+'</button>';
                        }
                        else {
                            return null;
                        }
                    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM