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();        
});
原文链接:https://www.f2er.com/jquery/180461.html

猜你在找的jQuery相关文章