Pipeline function Javascript concept question

Pipeline function Javascript concept question

sklugerskluger Posts: 1Questions: 1Answers: 0

https://datatables.net/examples/server_side/pipeline

I'm pretty sure this is a Javascript concept question but for the pipeline example, how do the cache variables inside the pipeline function maintain their values from previous calls if the pipeline function gets recalled on every table redraw?

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Its all about the scope of the variables. Near the top of the pipeline function you'll see:

        // Private variables for storing the cache
        var cacheLower = -1;
        var cacheUpper = null;
        var cacheLastRequest = null;
        var cacheLastJson = null;
    

    Those store the information about the last request. The function that is actually run when DataTables then executes the Ajax method has access to them (they are not new variables in that function - they are the variables that were set before).

    I found this page which does a nice job of explaining scope in Javascript.

    Does that make a bit more sense now? Happy to explain the pipeline function further if it would help.

    Allan

Sign In or Register to comment.