子表中的jTable动态自定义工具栏项

时间:2017-05-11 23:01:19

标签: jquery-jtable

我有一个jTable,每行有一个子表。在子表的工具栏标题上,我添加了一个自定义工具栏项。我想让那个工具栏项动态,如果已经有一些行我不希望它显示。我遇到了一个非常类似的主工具栏查询"添加新的"添加了一个在recordsLoaded上运行的函数的按钮:

以下是我的第一次尝试 - 它只是主表的字段条目,用于指定子表。然而," .find(....)" spec在我的情况下不起作用,因为我的是自定义工具栏项。我需要将什么作为.find标准?

由于

                Dance: {
                title: '',
                width: '4%',
                sorting: false,
                create: false,
                listClass: 'centreCol',
                display: function(book) {
                    var $img = $('<img src="Images/layers.png" title="Show associated dance entries" />');
                    //Open child table when user clicks the image
                    $img.click(function() {
                        var thisrow = $img.closest('tr'); //Parent row
                        if($('#BookTableContainer').jtable('isChildRowOpen',thisrow)) { // Clicking image a second time closes the child row
                            $('#BookTableContainer').jtable('closeChildRow',thisrow);
                        } else {
                            currentTitleID = book.record.DanceTitleID;
                            $('#BookTableContainer').jtable(
                                'openChildTable',
                                thisrow,
                                {
                                    title: 'Related Dance',
                                    toolbar: {
                                        items: [
                                            {
                                                icon: 'Images/add.png',
                                                text: 'New dance',
                                                tooltip: 'Add dance details',
                                                click: function() { CreateDanceDialog(); }
                                            }
                                        ]
                                    },
                                    actions: {
                                        listAction: 'BookPageData.php?action=listChildDances&DanceTitleID=' + currentTitleID,
//                                      createAction: 'dancesData.php?action=createAssignment',
//                                      deleteAction: 'dancesData.php?action=deleteAssignment'
                                    },
                                    recordsLoaded: function(event, data) {
                                        var rowCount = data.records.length;
                                        if (rowCount>0){
                                            $('#BookTableContainer').find('.jtable-toolbar-item.jtable-toolbar-item-add-record').remove();
                                        }
                                    },
                                    fields: {
                                        DanceID: { key: true, create: false, edit: false, list: false, visibility: 'hidden' },
                                        DanceTitleID: { type: 'hidden', defaultValue: currentTitleID },
                                        ChoreographerID: { title: 'Choreographer', width: '40%', options: function() { return ChoreographerOptions; } },
                                        FormationID: { title: 'Formation', width: '30%', options: function() { return FormationOptions; } },
                                        GenreID: { title: 'Genre', width: '30%', options: function() { return GenreOptions; } }
                                    }
                                },
                                function(data) { data.childTable.jtable('load'); }
                            );
                        }
                    });
                    //Return image to show on the person row
                    return $img;
                }
            },

1 个答案:

答案 0 :(得分:0)

试试这个

$('#BookTableContainer').find('.jtable-toolbar').remove();