Data-tables unable to reload on deletion of row ?

Data-tables unable to reload on deletion of row ?

sunildonsunildon Posts: 40Questions: 7Answers: 0
edited May 2014 in DataTables

Hi

Well i am not using any sort of plugin to delete . i am trying normally using ajax call but i don't know whats wrong Why datatable is not reloading it self after ajax call ?

Well i am trying to send additional parameters to controller delete method . so tried like this .

Please mention me if i am doing something wrong .

My code :

[code]
$(document).ready(function () {
var oTable = $('#myDataTable').dataTable({
"bProcessing": true,
"bDestroy": true,
"bServerSide": true,
"sAjaxSource": 'AjaxDataProvider',
"fnServerData": function (sSource, aoData, fnCallback)
{
$('#btnDeleteRow').click(function () {
delreason = prompt("Are u serious");
$.ajax({
"type": "GET",
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
//"/company/DeleteData/?start=" + delreason,
"url": "/company/DeleteData/?id=" + sel + "&ss=" + delreason,
"data": aoData,
"success": function (data)
{
debugger;
fnCallback(data);

                        $.ajax({
                            "type": "GET",
                            "dataType": 'json',
                            "contentType": "application/json; charset=utf-8",
                            "url": sSource,
                            "data": aoData,
                            "success": function (data) {
                                debugger;
                                fnCallback(data);
                            }
                        });
                    }
                });

            });

                debugger;
                $.ajax({
                    "type": "GET",
                    "dataType": 'json',
                    "contentType": "application/json; charset=utf-8",
                    "url": sSource,
                    "data": aoData,
                    "success": function (data) {
                        debugger;
                        fnCallback(data);
                    }
                });

        },
        "aoColumns": [

            {
                "sName": "ID",
                "bSearchable": false,
                "bSortable": false,
                "bVisible": false

            },
                                { "sName": "COMPANY_NAME" },
                                { "sName": "ADDRESS" },
                                { "sName": "TOWN" }
        ]

    });

$("#myDataTable tbody tr").live('click', function (event) {
var data1 = oTable.fnGetData(this);
sel = data1[0];
$("#myDataTable tbody tr").removeClass('row_selected');
$(this).addClass('row_selected');
});
});
[/code]
```
My controller code :
[code]
public ActionResult DeleteData(int id,string ss )
{
JQueryDataTableParamModel param = new JQueryDataTableParamModel();
//var value = Request.QueryString["start"];
var company = DataRepository.GetCompanies().FirstOrDefault(c => c.ID == id);

            DataRepository.GetCompanies().Remove(company);

            var result = DataRepository.GetCompanies().ToList();

            return Json(new
        {
            sEcho = param.sEcho,
            iTotalRecords = result.Count(),
            iTotalDisplayRecords = result.Count(),
            aaData = result
        },

                JsonRequestBehavior.AllowGet);

}
[/code]

Regards

This discussion has been closed.