Datatable table.fnUpdate两次触发动作

时间:2014-06-12 09:09:56

标签: ruby-on-rails datatable jquery-datatables

我在服务器端处理中实现数据表, 在控制器(ROR)中,我正在采取行动

def search_result
  render json: ExampleDatatable.new(view_context)
end

现在来自js我正在初始化它

var table = $("#example_list").DataTable({

    iDisplayLength: 10,
    bSort: true,
    bPaginate: true,
    sPaginationType: "full_numbers",
    //bFilter: false,
    bStateSave: true,
    bRetrieve: true,
    bDestroy: true,
    bProcessing: true,
    bServerSide: true,
    sAjaxSource: '/example/search__result'
});

我在这里得到的结果。 但我需要根据自定义搜索更新表(从视图中的表单输入)。 现在..

var new_table = $("#token_list").DataTable();
$(document).on("submit", "#example_form", function(e){
    e.preventDefault();
    var key1 = $("#_xyz").val();
    var key2 = $("#_abc").val();
    $.ajax({
        url: '/example/search_result',
        method: 'post',
        dataType: 'JSON',
        async: false,
        data:{
            "xyz": key1,
            "abc": key2

        },
        success: function (data) {
            for(i=0; i < data.aaData.length; i++){
                table.fnUpdate( data.aaData[i], i );
            }
            return false;

        },
        failure: function (msg) {
            console.log("Error in sending the data");
        }
    });
});

在ajax调用成功后,我收到搜索到的数据,但我认为fnUpdate search_result正在触发两次......旧数据将删除更新后的数据。 但我需要更新的数据。不是旧数据。

0 个答案:

没有答案