jsgrid多个自定义控件按钮? [英] jsgrid multiple custom control buttons?

查看:131
本文介绍了jsgrid多个自定义控件按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加多个自定义控件按钮,以便我可以向按钮添加自定义点击事件。我遇到的问题是只显示删除按钮。我希望每一行都显示编辑和删除按钮。我有以下代码:

I would like to add multiple custom control buttons so I can add a custom click event to the buttons. The issue I am having is the delete button is only shown. I would like both the edit and delete buttons shown in every row. I have the following code:

<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>

这篇关于jsgrid多个自定义控件按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆