首页 > 其他分享 >jsgrid多个自定义控件按钮?

jsgrid多个自定义控件按钮?

时间:2024-01-23 15:13:59浏览次数:20  
标签:控件 attr 自定义 title item width type id 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)

标签:控件,attr,自定义,title,item,width,type,id,jsgrid
From: https://www.cnblogs.com/roak/p/17982528

相关文章

  • Python的sort自定义compare函数
    记住这个规律:1.无论是什么,都先左侧的大,ifx>y:固定写法。2.大的放右边就return1;如果想要大的放左边就return-1;这里记忆是【-1,1】坐标轴上,-1在左侧,1在右侧 #默认sort是左小-右大,的return1#要排序大的,就右侧大的return1defcompare(x,y):ifx>y:......
  • c#dataGridView控件水平滚动条不显示的原因
    https://blog.csdn.net/weixin_44899642/article/details/128791899c#dataGridView控件水平滚动条不显示的原因1.最主要的在dataGridView控件属性中的ScrollBars是否设为BothBoth代表水平和垂直方向根据实际需求自动显示滚动条None代表水平和垂直都不显示滚动条Vertical代表......
  • DevExpress WinForms导航控件 - 交付更时尚、体验更好的业务应用(二)
    DevExpressWinForms的SideNavigation(侧边导航)和NavPanel(导航面板)可以帮助客户交付完全可模仿UI体验的业务解决方案,这些体验在当今流行的应用程序中都可找到。在上文中(点击这里回顾>>),我们为大家介绍了DevExpressWinForms导航控件中的折叠组件、导航栏组件等。接下来我们将继续......
  • Vue_中央事件总线EventBus传值&自定义MyEventBus
    一、EventBus的创建以及使用//1、在src的main.js中,加上以下代码importVuefrom'vue'Vue.prototype.$EventBus=newVue()//2、发送消息,使用Vue原型链引入this.$EventBus.$emit('getSumu',"sumu10086")//3、监听接收消息,使用Vue原型链引入this.$EventBus.$......
  • 自定义导航栏
    我们不同手机的导航栏不一样,这是为了确保我们每个手机都能看到我们导航栏的全部信息不会被遮挡,给不同机型进行样式适配 准备组件静态结构修改页面配置,隐藏默认导航栏,修改文字颜色样式适配->安全区域<scriptsetuplang="ts">//</script><template><viewclass......
  • springboot自定义更换启动banner动画
    springboot自定义更换启动banner动画......
  • 自定义vcpkg注册表(一)
    vcpkg提供自定义注册表的功能,主要用途可以是:公司私有库的注册表,自己对官方port的补充但是目前还不想提交到官方的port以及自己和官方对同一个库有不同的构建意见。在自定义注册表中新建port尽管我经常说vcpkg的本质是git和cmake的组合使用,但其实vcpkg还提供了vcpkg.exe和一整套......
  • VB6的OfficeMenu控件 - 开源研究系列文章
          这次将原来VB6中喜欢和使用到的OfficeMenu的控件做一个使用介绍。      上次介绍了VB6中的控件引擎,但是那个只针对基本的控件,这个OfficeMenu控件在当时是收费的,笔者找度娘好不容易才下载到一个免费版本,而且使用起来也非常的方便,在当时那个年代是笔者对于VB6中......
  • 界面控件DevExpress ASP.NET Data Grid组件 - 可快速处理各类型数据!(一)
    由DevExpress开发的快速且功能完整的ASP.NETWebForms的DataGrid组件,从全面的数据塑造和数据过滤选项到十多个集成数据编辑器,该套件提供了帮助用户构建极佳数据所需的一些,没有限制!P.S:DevExpressASP.NETWebForms Controls拥有针对Web表单(包括报表)的110+种UI控件,可利用轻量级......
  • 自定义按钮模板
    自定义按钮模板本文同时为b站WPF课程的笔记,相关示例代码对应09上半节课自定义模板对于当前的这个样式不满意——想要自己控制它这个控件长什么样子比如在一节课中,为了实现圆角按钮,我们是从网上面抄了一段代码过来那么,如何建立一种自带圆角的按钮模板呢?<ButtonWidth="300"......