我们如何在Delete Action中发送不是Key的字段

时间:2015-06-03 10:18:41

标签: ajax jquery-jtable

我需要在删除操作中发送未标记为Key的字段。在我的案例中,我想使用多个字段删除一行。

2 个答案:

答案 0 :(得分:1)

我找到了答案。我们需要在jtable

的字段部分添加此代码
customDelete: {
    title: '',
    width: '0.3%',
    display: function(data) {
    var $but = $('<button title="delete" class="jtable-command-button jtable-delete-command-button" >delete</button>');
               $but.click(function(){
                   var $dfd = $.Deferred();
                   if(data.record.configType == 'global')
                   {
                       alert('Global Type Configuration are not allowed for deletion.')
                       return false;
                   }
                   if (confirm('Are you sure you want to delete this?')) {
                         $.ajax({
                            url: '/admin/configuration/delete',
                            type: 'POST',
                            dataType: 'json',
                            data: data.record,
                            success: function (data) {
                                $dfd.resolve(data);
                                $('#Container').jtable('load') ;

                            },
                            error: function () {
                                $dfd.reject();
                            }
                        });
                }
            });
            return $but;
        }
    },
}

答案 1 :(得分:0)

您可以编写自定义删除功能而不仅仅是URL。而且,在doin中添加要通过ajax发送的数据中的字段。请参阅以下代码以及文档http://www.jtable.org/demo/FunctionsAsActions

$('#Container').jtable({
        //...other code
        actions: {
            deleteAction: function (postData) {
                    console.log("deleting from custom function...");
                    //Attach your values to postData... 
                    //make sure you collect it in controller/code
                    postData.customData = $('#myinput').val();
                    return $.Deferred(function ($dfd) {
                        $.ajax({
                            url: '/Demo/DeleteStudent',
                            type: 'POST',
                            dataType: 'json',
                            data: postData,
                            success: function (data) {
                                $dfd.resolve(data);
                            },
                            error: function () {
                                $dfd.reject();
                            }
                        });
                    });
                },
            //...other actions
        },
    });

    //Load student list from server
    $('#Container').jtable('load');
});