jquery - 如何使用 SlickGrid 插件在每一行上创建删除按钮?

标签 jquery slickgrid

如何使用 SlickGrid 插件在每一行上创建删除按钮?我需要一个可以删除整个相应行的按钮。

最佳答案

使用列格式化程序来完成此操作。

var column = {id:delCol, field:'del', name:'Delete', width:250, formatter:buttonFormatter}

//Now define your buttonFormatter function
function buttonFormatter(row,cell,value,columnDef,dataContext){  
    var button = "<input class='del' type='button' id='"+ dataContext.id +"' />";
    //the id is so that you can identify the row when the particular button is clicked
    return button;
    //Now the row will display your button
}

//Now you can use jquery to hook up your delete button event
$('.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
    dataView.deleteItem(id);
    //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'
    grid.invalidate();        
});

关于jquery - 如何使用 SlickGrid 插件在每一行上创建删除按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9784400/

相关文章:

javascript - 如何在 SlickGrid 中返回特定的单元格值?

javascript - 如何从 Base 64 字符串获取 MIME-TYPE?

javascript - 对 MVC 4 Controller 操作的同步 javascript 调用

jQuery 验证插件在 IE 中失败

javascript - 对于多个 SlickGrid 绑定(bind)到 onSelectedRowsChanged 时得到错误的实例

javascript - SlickGrid 追加具有不同 ID 的新行

javascript - 使用多个 Deferred 和 Promises - jquery

javascript - 我的代码在 jquery mobile 1.0 中运行良好但在 1.4.2 中运行不正常

javascript - 光滑网格列未正确呈现

javascript - Slickgrid - 自定义列排序器