Update datatables (JQuery) when button is clicked

后端 未结 5 1498
遇见更好的自我
遇见更好的自我 2021-02-09 01:37

I\'ve created a simple form and I\'m using the Datatables jQuery plugin to display some data in it. Data are being populated by a php script (process.php) which returns the prop

5条回答
  •  再見小時候
    2021-02-09 02:36

    At last, I found the solution! There were 2 problems in my JQuery code:

    1. I had to add the fnReloadAjax() code after the script tags which load datatables and before the $(document).ready() statement.
    2. I had to alter the JQuery code of my submit button (no need for an AJAX call, only fnReloadAjax() is necessary).

    Thank you both Stefan & mbeasley!!

    JQuery code now is:

    //
    // fnReloadAjax() code      
    //
        $.fn.dataTableExt.oApi.fnReloadAjax = function ( oSettings, sNewSource, fnCallback, bStandingRedraw )
        {
            if ( typeof sNewSource != 'undefined' && sNewSource != null )
            {
                oSettings.sAjaxSource = sNewSource;
            }
            this.oApi._fnProcessingDisplay( oSettings, true );
            var that = this;
            var iStart = oSettings._iDisplayStart;
            var aData = [];
    
            this.oApi._fnServerParams( oSettings, aData );
    
            oSettings.fnServerData( oSettings.sAjaxSource, aData, function(json) {
                /* Clear the old information from the table */
                that.oApi._fnClearTable( oSettings );
    
                /* Got the data - add it to the table */
                var aData =  (oSettings.sAjaxDataProp !== "") ?
                    that.oApi._fnGetObjectDataFn( oSettings.sAjaxDataProp )( json ) : json;
    
                for ( var i=0 ; i

提交回复
热议问题