jsgrid多個自定義控件按鈕?

我想添加多個自定義控件按鈕,這樣我就可以向這些按鈕添加一個自定義單擊事件。我遇到的問題是刪除按鈕只顯示出來。我希望編輯和刪除按鈕都顯示在每一行。我有以下代碼:

<script>
    $( document ).ready(function() {
      $("#jsGrid").jsGrid({
           height: "auto",
           width: "100%",
           sorting: true,
           paging: true,
           autoload: true,
           pageSize: 10,
           pageButtonCount: 5,
           deleteConfirm: "Do you really want to delete your job listing?",
           controller: {
               loadData: function(filter) {
                   return $.ajax({
                       type: "GET",
                       url: "<?php echo site_url('/job/getjobs/'.$this->session->employer_id); ?>",
                       data: filter
                   });
               },
           },
           fields: [
               { name: "id", title: "id", type: "text", visible: false, width: 100 },
               { name: "title", title: "Title", type: "text", width: 100 },
               { name: "created_on", title: "Created On", type: "text", width: 100 },
               { name: "salary", title: "Salary", type: "text", width: 100 },
               { name: "is_active", type: "text", title: "Is Active", width: 100 },
               { type: "control", width: 100, editButton: false, deleteButton: false,
                 itemTemplate: function(value, item) {
                    var $result = jsGrid.fields.control.prototype.itemTemplate.apply(this, arguments);

                    var $customButton = $("<button>").attr({class: "customGridDeletebutton jsgrid-button jsgrid-edit-button"})
                      .click(function(e) {
                        alert("ID: " + item.id);
                        e.stopPropagation();
                      });

                    return $result.add($customButton);
                },
                itemTemplate: function(value, item) {
                  var $result = jsGrid.fields.control.prototype.itemTemplate.apply(this, arguments);

                  var $customButton = $("<button>").attr({class: "customGridEditbutton jsgrid-button jsgrid-delete-button"})
                    .click(function(e) {
                      alert("Title: " + item.title);
                      e.stopPropagation();
                    });

                    return $result.add($customButton);
                }
              }
           ]
       });
    });

</script>
<script>
    $( document ).ready(function() {
      $("#jsGrid").jsGrid({
           height: "auto",
           width: "100%",
           sorting: true,
           paging: true,
           autoload: true,
           pageSize: 10,
           pageButtonCount: 5,
           deleteConfirm: "Do you really want to delete your job listing?",
           controller: {
               loadData: function(filter) {
                   return $.ajax({
                       type: "GET",
                       url: "<?php echo site_url('/job/getjobs/'.$this->session->employer_id); ?>",
                       data: filter
                   });
               },
           },
           fields: [
               { name: "id", title: "id", type: "text", visible: false, width: 100 },
               { name: "title", title: "Title", type: "text", width: 100 },
               { name: "created_on", title: "Created On", type: "text", width: 100 },
               { name: "salary", title: "Salary", type: "text", width: 100 },
               { name: "is_active", type: "text", title: "Is Active", width: 100 },
               { type: "control", width: 100, editButton: false, deleteButton: false,
                 itemTemplate: function(value, item) {
                    var $result = jsGrid.fields.control.prototype.itemTemplate.apply(this, arguments);

                    var $customEditButton = $("<button>").attr({class: "customGridEditbutton jsgrid-button jsgrid-edit-button"})
                      .click(function(e) {
                        alert("ID: " + item.id);
                        e.stopPropagation();
                      });

                   var $customDeleteButton = $("<button>").attr({class: "customGridDeletebutton jsgrid-button jsgrid-delete-button"})
                    .click(function(e) {
                      alert("Title: " + item.title);
                      e.stopPropagation();
                    });

                    return $("<div>").append($customEditButton).append($customDeleteButton);
                    //return $result.add($customButton);
                },
              }
           ]
       });
    });

</script>
{
    type: "control", editButton: false, deleteButton: false,
    itemTemplate: function(value, item) {
        var $iconPencil = $("<i>").attr({class: "glyphicon glyphicon-pencil"});
        var $iconTrash = $("<i>").attr({class: "glyphicon glyphicon-trash"});

        var $customEditButton = $("<button>")
            .attr({class: "btn btn-warning btn-xs"})
            .attr({role: "button"})
            .attr({title: jsGrid.fields.control.prototype.editButtonTooltip})
            .attr({id: "btn-edit-" + item.id})
            .click(function(e) {
                alert("ID: " + item.id);
                // document.location.href = item.id + "/edit";
                e.stopPropagation();
            })
            .append($iconPencil);
        var $customDeleteButton = $("<button>")
            .attr({class: "btn btn-danger btn-xs"})
            .attr({role: "button"})
            .attr({title: jsGrid.fields.control.prototype.deleteButtonTooltip})
            .attr({id: "btn-delete-" + item.id})
            .click(function(e) {
                alert("ID: " + item.id);
                // document.location.href = item.id + "/delete";
                e.stopPropagation();
            })
            .append($iconTrash);

        return $("<div>").attr({class: "btn-toolbar"})
            .append($customEditButton)
            .append($customDeleteButton);
    }
}

jsgrid多個自定義控件按鈕?-騰訊雲開發者社區-騰訊雲 (tencent.com)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章