How to update datatable rows from modal
everything is working fine. I have just problem datatable not refresh after modal close.
I update the current datatable row via modal and values is coming and going right, but when click the update modal button datatables draw or sort problem.
how can I update datatables re draw after modal closed
<table id="tblmainMenu" class="table table-responsive-sm table-condensed table-bordered">
<thead>
<tr>
<th style='visibility:collapse'>@Html.DisplayNameFor(model => model.CloudMainMenuViewModelClass.ID)</th>
<th>@Html.DisplayNameFor(model => model.CloudMainMenuViewModelClass.MAINMENUCODE)</th>
<th>@Html.DisplayNameFor(model => model.CloudMainMenuViewModelClass.MAINMENUNAME)</th>
<th>@Html.DisplayNameFor(model => model.CloudMainMenuViewModelClass.ICON)</th>
<th>Aksiyon</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.CloudMainMenuList)
{
<tr>
<td style='visibility:collapse'>@item.ID</td>
<td>@item.MAINMENUCODE</td>
<td>@item.MAINMENUNAME</td>
<td>@item.ICON</td>
<td>
<a class='fa fa-list' id="btnAnaMenuUpdate" onclick="GetMainMenu(@item.MAINMENUCODE)" style='color: #428bca;' data-toggle='tooltip' title='UpdateMenu' href='javascript:;'></a> |
</td>
</tr>
}
</tbody>
</table>
<!-- Menü Update Modal -->
<div class="modal fade" id="MainMenuModal" tabindex="-1" role="dialog" aria-labelledby="myModalLable" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" style="margin: 0 auto;" id="ModalTitle">Ana Menü Ekle</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="mConta">
<div class="form-group">
<div class="col-sm-12">
<input id="txtID" style="display:none" type="text" placeholder="Main Menu ID" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input id="txtMainMenuCode" class="form-control tooltip-test" title="Main Menu No" type="text" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input id="txtMainMenuName" class="form-control tooltip-test" type="text" title="Main Menu Adı" />
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input id="txtIcon" type="text" class="form-control tooltip-test" title="Main Icon" />
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="btnClose" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" id="btnSave">
Save <span class="fa fa-floppy-o" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-success" id="btnUpdate" onclick="UpdateMainMenu()">
Update <span class="fa fa-floppy-o" aria-hidden="true"></span>
</button>
</div>
</div>
</div>
</div>
<!-- Get MenüInfo -->
function GetMainMenu(MAINMENUCODE) {
$.ajax({
url: "/Sistem/GetMainMenuAjax",
data: { MAINMENUCODE: MAINMENUCODE },
type: "Get",
contentType: "application/json;charset=UTF-8",
dataType: "Json",
success: function (result) {
$('#txtID').val(result.data.ID);
$('#txtMainMenuCode').val(result.data.MAINMENUCODE);
$('#txtMainMenuName').val(result.data.MAINMENUNAME);
$('#txtIcon').val(result.data.ICON);
$('#btnSave').hide();
$('#btnUpdate').show();
$('#MainMenuModal .close').css('display', 'none');
$('#MainMenuModal').modal('show');
}
})
}
<!-- Update MenüInfo -->
function UpdateMainMenu() {
var table = $('#tblmainMenu').DataTable();
table.destroy();
var model = new Object();
model.ID = $('#txtID').val(),
model.MAINMENUCODE = $('#txtMainMenuCode').val(),
model.MAINMENUNAME = $('#txtMainMenuName').val(),
model.ICON = $('#txtIcon').val();
$.ajax({
url: "/Sistem/UpdateMainMenu",
type: "Post",
data: JSON.stringify(model),
contentType: "application/json; charset=UTF-8",
dataType: "json",
success: function (response) {
toastr.success(response.message);
table.row('selected').cell(':eq(1)').data($('#txtMainMenuCode').val());
table.row('selected').cell(':eq(2)').data($('#txtMainMenuName').val());
table.row('selected').cell(':eq(3)').data($('#txtIcon').val());
table.draw();
}
});
}