Hi,
I am using DataTables 1.9.4 version. I am developing MVC project. I list categories with using DataTables properly. I add two custom buttons which are Delete and Edit button. When I click the edit button fancybox edit window open. When I change some fields values then I click submit button; Close the fancybox window and update the categories list by fnDraw() method. Thats so good until click the other row edit button. When I click the edit button secondly, call the categoryedit method (HttpGet) two times then open edit form. If I click submit button and repeat click the other row edit button, call the categoryedit method (HttpGet) three times... Increase the call time to categoryedit method. How to avoid this situation ? When I remove the fnDraw() method I avoid this problem but I want to refresh category list.
CategoryList Form (Script Region)
I am using DataTables 1.9.4 version. I am developing MVC project. I list categories with using DataTables properly. I add two custom buttons which are Delete and Edit button. When I click the edit button fancybox edit window open. When I change some fields values then I click submit button; Close the fancybox window and update the categories list by fnDraw() method. Thats so good until click the other row edit button. When I click the edit button secondly, call the categoryedit method (HttpGet) two times then open edit form. If I click submit button and repeat click the other row edit button, call the categoryedit method (HttpGet) three times... Increase the call time to categoryedit method. How to avoid this situation ? When I remove the fnDraw() method I avoid this problem but I want to refresh category list.
CategoryList Form (Script Region)
<script>
var asInitVals = new Array();
var oTable;
var slider_value = true;
$(document).ready(function () {
$("#IS_ENABLED").change(function () {
slider_value = $("#IS_ENABLED").val();
oTable.fnDraw(false);
});
$(".ui-link").each(function(){
$(this).attr("rel","external");
});
oTable = $('#tableId').dataTable({
"bProcessing": true,
"bServerSide": true,
//"sEcho": 3,
"bDeferRender": true,
"bSort": true,
"bAutoWidth": true,
//"bStateSave": true,
"bJQueryUI": true,
"bPaginate": true,
"sAjaxSource": "/Admin/GetCategories",
"fnServerParams": function (aoData) {
aoData.push(
{ "name": "status", "value": slider_value });
},
"bRetrieve": true,
"sPaginationType": "full_numbers",
"oLanguage": {
"sLengthMenu": "@Config.Get(ConfigKey.MenuPage)",
"sZeroRecords": "@Config.Get(ConfigKey.ZeroResult)",
"sInfo": "@Config.Get(ConfigKey.PagingInfo)",
"sInfoEmpty": "@Config.Get(ConfigKey.PagingZero)",
"sInfoFiltered": "@Config.Get(ConfigKey.PageFilter)",
"sProcessing": "@Config.Get(ConfigKey.DataTableLoading)",
"sLoadingRecords": "@Config.Get(ConfigKey.DataTableLoading2)",
"sSortAscending" : "@Config.Get(ConfigKey.DataTableAscSort)",
"sSortDescending": "@Config.Get(ConfigKey.DataTableDescSort)",
"sEmptyTable": "@Config.Get(ConfigKey.DataTableEmpty)",
"sSearch": "@Config.Get(ConfigKey.DataTableSearch)",
"oPaginate": {
"sFirst": "@Config.Get(ConfigKey.DataTableFirst)",
"sLast": "@Config.Get(ConfigKey.DataTableLast)",
"sNext": "@Config.Get(ConfigKey.DataTableNext)",
"sPrevious": "@Config.Get(ConfigKey.DataTablePrevious)"
}
},
"aoColumns": [
{ "mDataProp": "DESCCAT" },
{ "mDataProp": "DESCCAT_EN" },
{
"mDataProp": "SIDCATDEL",
"sTitle": "#",
"fnRender": function(obj) {
var catId = obj.aData.SIDCATDEL;
var deletebutton = '<input type="button" class="icon-remove" onClick="DeleteCategory(' + catId + ') "></input>';
return deletebutton;
}
},
{
"mDataProp": "SIDCATEDIT",
"sTitle": "#",
"fnRender": function(obj) {
var catId = obj.aData.SIDCATEDIT;
//var editbutton = '<a href="/Kategori-duzenle/' + catId + '" class="icon-edit"></a>';
var editbutton = '<input type="button" class="icon-edit" onClick="EditCategory(' + catId + ') "></input>';
return editbutton;
}
}
],
"fnDrawCallback": function() {
$(".add").fancybox({
'width': '40%',
'height': '90%',
'autoScale': false,
'type': 'iframe',
'padding': '0',
'showCloseButton': true,
'enableEscapeButton': true,
'beforeClose': function () {
//oTable.fnDraw(false);
}
});
}
});
});
function EditCategory(categoryId) {
$(".icon-edit").fancybox({
'width': '40%',
'height': '90%',
'autoScale': false,
'type': 'iframe',
'padding': '0',
'href': '/Kategori-duzenle/'+categoryId+'',
'showCloseButton': true,
'enableEscapeButton': true,
'beforeClose': function () {
oTable.fnDraw();
}
});
return false;
}
</script>