Row show/hide locally on server side query

Row show/hide locally on server side query

GeorgeHelmkeGeorgeHelmke Posts: 44Questions: 16Answers: 0

Here a peach for you:
I am getting records from a server side ajax query.
The user then has 50 or so records to stare at.
I want them to have a button that limits the amount of records shown , without having to do another server hit. It just goes through the table, and hides/shows existing rows based on criteria I set up.

I have tried $.fn.dataTableExt.afnFilter.push( blah blah blah.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    based on criteria I set up

    That is critical - what is that criteria? You could potentially use search() or column().search() for simple logic for example.

    server side ajax query

    Are you using server-side processing or client-side processing (serverSide)? With server-side, every draw will always cause an Ajax request in DataTables, there is no way around that as it is designed that way.

    Allan

  • GeorgeHelmkeGeorgeHelmke Posts: 44Questions: 16Answers: 0

    Server side - so I'll sort that out myself with the tools I have. Thanks for a firm answer, nothing better than that.

    Criteria. The first I did was just try to make all rows disappear:
    $.fn.dataTableExt.afnFiltering.push(
    function (settings, data, dataIndex) {
    return false;
    }

    Here are the definitions to set context:

        editorSalesLine = new $.fn.dataTable.Editor({
            ajax: "@Url.Action("Save", "SalesLine")",
            table: "#SalesLinePopupTable",
            fields: [
                        { type: "readonly", label: "DisplayCategory:", name: "DisplayCategory" },
                        { type: "readonly", label: "@ResHelper.Loc("No_"):", name: "No_" },
                        { type: "readonly", label: "@ResHelper.Loc("Description"):", name: "Description" },
                        { type: "readonly", label: "@ResHelper.Loc("UnitPrice"):", name: "UnitPrice" },
                        { label: "@ResHelper.Loc("LineDiscount"):", name: "LineDiscount" },
                        { label: "@ResHelper.Loc("Pages"):", name: "Pages" }, //needs to change to PAGES
                        { label: "@ResHelper.Loc("Quantity"):", name: "Quantity" },
                        { type: "readonly", label: "@ResHelper.Loc("LineAmount"):", name: "LineAmount" },
                        { type: "readonly", label: "@ResHelper.Loc("Additional_Quantity"):", name: "Additional_Quantity" },
                        { type: "readonly", label: "@ResHelper.Loc("Additional_Quoted_Price"):", name: "Additional_Quoted_Price" },
                        { type: "readonly", label: "@ResHelper.Loc("External_Job_Description"):", name: "External_Job_Description" },
                        { type: "readonly", label: "@ResHelper.Loc("Document_Type"):", name: "Document_Type" },
                        { type: "readonly", label: "@ResHelper.Loc("DocumentNo_"):", name: "DocumentNo_" },
                        { type: "readonly", label: "@ResHelper.Loc("LineNo_"):", name: "LineNo_" }
            ]
        });
    
        var oLanguage = {
            "sInfo": "@ResHelper.Loc("ShowingPageOfPage")",
            "sSearch": "@ResHelper.Loc("Search")",
            "sZeroRecords": "@ResHelper.Loc("ZeroRecords")",
            "sLengthMenu": "@ResHelper.Loc("LengthMenu")",
            "sInfoEmpty": "@ResHelper.Loc("InfoEmpty")",
            "sInfoFiltered": "@ResHelper.Loc("InfoFiltered")",
            "oPaginate": {
                "sNext": "@ResHelper.Loc("Next")",
                "sPrevious": "@ResHelper.Loc("Previous")"
            }
        };
    
        tableSalesLine = $('#SalesLinePopupTable').DataTable({
            bServerSide: true,
            bProcessing: true,
            "deferRender": true,
            bFilter: false,
            bPaginate: false,
            bLengthChange: false,
            bInfo: false,
            sServerMethod: "POST",
            sAjaxSource: "@Url.Action("AllWithWares", @ControllerName)",
            "fnServerParams": function (aoData) {
                aoData.push({ "name": "document_type", "value": document_type });
                aoData.push({ "name": "id", "value": id });
                aoData.push({ "name": "pordertype", "value": pordertype });
            },
            aoColumns: aoSalesLineColumnsSetup,
            "oLanguage": oLanguage         }
        );
    
  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Since you are using server-side processing the custom filtering functions in $.fn.dataTableExt.afnFiltering shouldn't even be called. The reason for that is that in server-side processing mode, filtering is entirely done by the server.

    Regards,
    Allan

This discussion has been closed.