1

I found so little info on StateInitDone out there I would like some confirmation.


I have code in the CSR OnPostRender which creates (non-CSR) DOM elements (easter-eggs) on screen;
I have dealt with all the MDS navigation issues using the asyncDeltaManager beginRequest & endRequest functions, they make it so DOM elements are only visible on the one page (DOM elements are not removed on MDS navigation)

letter I : pronounced as 'ei' in the Dutch language meaning 'egg'

That all works with only 3 JSLinks to one external (private CDN) JS file (SharePoint Online can): https://www.youtube.com/embed/jsQVSR6WOQ8

Next problem:

Clicking a check-box fires the OnPostRender (ofcourse), which is fine for CSR content,
but I do not want my custom stuff to run again.

Note: Whereas OnLoad the OnPostRender fires for all WebParts on screen

onclick only the OnPostRender for the associated WebPart is executed.

The ctx object gives 2 promising named keys:

On tracing, ctx.StateInitDone seems to be false in OnPostRender, also in MDS navigation.

It is true once the page has finished (and remains so on checkbox interactions)

So I now have in OnPostRender :

   if (!ctx.StateInitDone) iCSR.iHunt.hideEggBehind(ctx.view);

the function itself does the check if DOMcontent needs to be added

Questions

Another SharePoint bug that cropped up, those Checboxes are also displayed for user who do not have edit rigths...

  • just out of curiosity, what fun stuff are you creating? See lots of questions these days from you on CSR :) – Akhoy Mar 21 '16 at 15:44
  • When you use a tool for things no-one else uses it for you learn the most... youtube.com/embed/jsQVSR6WOQ8 – Danny '365CSI' Engelman Mar 21 '16 at 21:47
0

The onDataRefreshCompleted seems to be a callback from what I can see in INPLVIEW.js

If you look in the CLVPRefreshCore function, its used in the req.onreadystatechange ( req is a XMLHttpRequest ) :

if (req.readyState == 4 && typeof clvp.ctx.onDataRefreshCompleted == 'function') {
            callback = clvp.ctx.onDataRefreshCompleted;
            clvp.ctx.onDataRefreshCompleted = null;
   }

I just a did quick test with the AJAXRefreshView function and it was called:

g_ctxDict["ctx39"].onDataRefreshCompleted = function() {
    console.log("called");
};

var evt = {
    currentCtx: g_ctxDict["ctx39"],
    csrAjaxRefresh: true
};

AJAXRefreshView(evt, true);

From what I can find on StateInitDone it does not look like it does nothing except from reset some values on the ctx.

In the CLVPRefreshCore function from INPLVIEW.js under the onreadystatechange it does check the StateInitDone variable between OnPreRender and PostRender from the looks of it:

if (groupBody != null) {
     ...
    if (groupBody.getAttribute("isLoaded") != null) {
    ...
        if (!clvp.ctx.StateInitDone) ctxInitItemState(clvp.ctx);

And the ctxInitItemState from INIT.js

function ctxInitItemState(ctxCur) {
    ctxCur.TotalListItems = 0;
    ctxCur.CurrentSelectedItems = 0;
    ctxCur.LastSelectableRowIdx = 0;
    ctxCur.StateInitDone = true;
}
  • Cool,that means I can simplify some iCSR code where I did polling. Fun how creating fun stuff learns you more then any course or project, Anders, if you want my easter egg code, contact me at danny@engelman.nl – Danny '365CSI' Engelman Mar 21 '16 at 15:00
  • Looks cool @DannyEngelman :) Btw, you can get the "completed context" in the onDataRefreshCompleted = function(completedCtx) – Anders Aune Mar 21 '16 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.