简体   繁体   English

如何通过确认在slickgrid的每一行上创建删除按钮?

[英]How do I create a delete button on every row in slickgrid with confirmation?

As the title said it, how do I do it?, I am using this button created by jiri: 正如标题所说,我该怎么做?,我正在使用jiri创建的这个按钮:

How do i create a delete button on every row using the SlickGrid plugin? 如何使用SlickGrid插件在每一行上创建删除按钮?

when I add an if(confirmation(msg)) inside the function it repeats me the msg ALOT maybe its because i refresh-ajax the table with each modification. 当我在函数内添加一个if(确认(msg))时,它重复了我的msg ALOT可能是因为我刷新-ajax表每次修改。

ask me if you need more info, I am still noob here in stackoverflow :P (also if there is someway to "kill" the function) 问我是否需要更多信息,我仍然在堆栈溢出中的noob:P(如果有一些“杀死”功能)

here is the button, iam using(link) i added the idBorrada to check whetever the id was already deleted and dont try to delete it twice, also here is a confirm, but when i touch cancel it asks me again. 这是按钮,我使用(链接)我添加了idBorrada来检查id已被删除,并且不要尝试删除它两次,这里也是确认,但当我触摸取消它再次问我。

$('.del').live('click', function(){ var me = $(this), id = me.attr('id'); //assuming you have used a dataView to create your grid //also assuming that its variable name is called 'dataView' //use the following code to get the item to be deleted from it if(idBorrada != id && confirm("¿Seguro desea eleminarlo?")){ dataView.deleteItem(id); Wicket.Ajax.ajax({"u":"${url}","c":"${gridId}","ep":{'borrar':JSON.stringify(id, null, 2)}}); //This is possible because in the formatter we have assigned the row id itself as the button id; //now assuming your grid is called 'grid' //TODO grid.invalidate(); idBorrada= id; } else{ }; });

and i call the entire function again. 然后我再次调用整个函数。 hope that help, sorry for the grammar its not my native language 希望有所帮助,对不起语法而不是我的母语

Follow these steps, 跟着这些步骤,

  1. Add a delete link for each row with of the columns object as follows, 为列对象的每一行添加删除链接,如下所示,

     <lang=javascript var columns = { id: "Type", name: "Application Type", field: "ApplicationType", width: 100, cssClass: "cell-title", editor: Slick.Editors.Text, validator: requiredFieldValidator, sortable: true }, { id: "delete", name: "Action", width: 40, cssClass: "cell-title", formatter: Slick.Formatters.Link } ]; 



  2. Add a Link Formatter inside slick.formatters.js as follows, 在slick.formatters.js中添加一个Link Formatter,如下所示,

     "Formatters": { "PercentComplete": PercentCompleteFormatter, "YesNo": YesNoFormatter, "Link": LinkFormatter } function LinkFormatter(row, cell, value, columnDef, dataContext) { return "<a style='color:#4996D0; text-decoration:none;cursor:pointer' onclick='DeleteData(" + dataContext.Id + ", " + row + ")'>Delete</a>"; } 
  3. Add the following delete function in javascript 在javascript中添加以下删除功能

function DeleteData(id, rowId) {
    var result = confirm("Are you sure you want to permenantly delete this record!");
    if (result == true) {
        if (id) {
            $.ajax({
                type: "POST",
                url: "DeleteURL",
                data: { id: id },
                dataType: "text",
                success: function () {
                },
                error: function () {
                }
            });
        }
        dataView.deleteItem(id);
        dataView.refresh();
    }
}

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

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