How to keep the iDisplayLength same after click of button

How to keep the iDisplayLength same after click of button

sylvia090sylvia090 Posts: 1Questions: 1Answers: 0

I have a datatable that I initialise using the below code and a few dropdown to search data. On click of submit button I want to keep the iDisplayLength to what user had selected before click of button
Code as below:

    $(document).ready(function() {
        $.ajaxSetup({
            cache: false
        });


        var selappId = $("#ddlApplication").val();
        var selprojId = $("#ddlProjects").val();
        var selrelId = $("#ddlRelease").val();
        var selreqTypeId = $("#ddlRequestType").val();
        var selstateId = $("#ddlState").val();
        var selcompId = $("#ddlCompany").val();
        var selfrmdt = $("#txtFromDate").val();
        var seltodt = $("#txtToDate").val();
        var selrequestedby = $("#txtRequestedBy").val();
        var selassignedto = $("#txtAssignedTo").val();

        var oTable = $('#tblData').DataTable({
            "filter": false,
            "pagingType": "simple_numbers",
            "bAutoWidth": false,
            "columnDefs": [
            { orderable: false, targets: -1 }
            ],//remove sorting for last col
            "orderClasses": false,
            "order": [[8, "desc"]],//requestedat desc by default
            "bInfo": true,
            "bProcessing": false,
            "bServerSide": true,
            "sAjaxSource": "PublicWebServices/TfsReportsWebservice.asmx/GetTableData",
            "fnServerData": function(sSource, aoData, fnCallback) {
                aoData.push({ "name": "ApplicationId", "value": selappId });
                aoData.push({ "name": "ProjectId", "value": selprojId });
                aoData.push({ "name": "ReleaseId", "value": selrelId });
                aoData.push({ "name": "RequestTypeId", "value": selreqTypeId });
                aoData.push({ "name": "StateId", "value": selstateId });
                aoData.push({ "name": "CompanyName", "value": selcompId });
                aoData.push({ "name": "FromDate", "value": selfrmdt });
                aoData.push({ "name": "ToDate", "value": seltodt });
                aoData.push({ "name": "RequestedBy", "value": selrequestedby });
                aoData.push({ "name": "AssignedTo", "value": selassignedto });
                $.ajax({
                    "dataType": 'json',
                    "contentType": "application/json; charset=utf-8",
                    "type": "GET",
                    "url": sSource,
                    "data": aoData,
                    "success": function(msg) {
                        var json = jQuery.parseJSON(msg.d);
                        fnCallback(json);
                        $("#tblData").show();
                    },
                    error: function(xhr, textStatus, error) {
                        if (typeof console == "object") {
                            console.log(xhr.status + "," + xhr.responseText + "," + textStatus + "," + error);
                        }
                    }
                });
            },
            //fnDrawCallback: function () {
            //    $('.image-details').bind("click", showDetails);
            //}
        });

        $("#ddlApplication").bind("change", function () {
            BinReleaseData();
        });


        $("#btnSubmit").bind("click",function(e) {
            //oTable.fnReloadAjax();
            selappId = $("#ddlApplication").val();
            selprojId = $("#ddlProjects").val();
            selrelId = $("#ddlRelease").val();
            selreqTypeId = $("#ddlRequestType").val();
            selstateId = $("#ddlState").val();
            selcompId = $("#ddlCompany").val();
            selfrmdt = $("#txtFromDate").val();
            seltodt = $("#txtToDate").val();
            selrequestedby = $("#txtRequestedBy").val();
            selassignedto = $("#txtAssignedTo").val();
           // oTable.ajax.reload(null, false); // user paging is not reset on reload
            // oTable.fnReloadAjax();
            var oSettings = oTable.settings();
            oSettings._iDisplayLength = 50;
               // oTable.fnDraw();
        });


        //BinReleaseData();
    });

    function BinReleaseData() {
        var applicationId = $('#ddlApplication').val();
        if (applicationId > 0) {
            $("#ddlRelease").get(0).options.length = 0;
            $("#ddlRelease").get(0).options[0] = new Option("Loading names", "-1");

            $.ajax({
                type: "POST",
                url: "TfsReportsTable.aspx/GetNames",
                data: "{applicationId:" + applicationId + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    var mydata = JSON.parse(data.d);
                    $("#ddlRelease").get(0).options.length = 0;
                    $("#ddlRelease").get(0).options[0] = new Option("Select release", "");

                    $.each(mydata, function (i) {
                        var isSelected = '';
                        //if (selrelId  !=undefined && selrelId == mydata[i].Id) {
                        //    isSelected = 'selected';
                        //}
                        var optionhtml = '<option value="' + mydata[i].Id + '">' + mydata[i].Name + '</option>';
                        $("#ddlRelease").append(optionhtml);
                    });
                },

                error: function() {
                    $("#ddlRelease").get(0).options.length = 0;
                    alert("Failed to load names");
                }
            });
        }
    }
</script>
This discussion has been closed.