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

查看:334
本文介绍了如何使用SlickGrid插件在每一行上创建一个删除按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do i create a delete button on every row using the SlickGrid plugin? I need a button that can delete the whole corresponding row.

推荐答案

使用列格式化程序即可完成此操作.

Use your column formatter to get this done.

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();        
});

这篇关于如何使用SlickGrid插件在每一行上创建一个删除按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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