Javascript after ajax refresh

  

Hey team,

I've been around an issue and would like to share it with you to know what is the best approach.

I have an expression with some JavaScript on it. That Javascript changes the title of one BulkList when I mouse hover it. 

The thing is that the BulkList is in a header of a record list. Every time I refresh the record list, for example to apply a filter, I loose the JavaScript I applied to the BulkList, basically its like the BulkList refreshes and maybe changes its ID?

What would be the best approach for this issue?


Thanks a lot in advance team,

VC

Hello Vincent,
Maybe you can have your header expression outside of the container that have the record list and when using the AJAX refresh, refresh only the record list container.

Best Regards

Paulo Zacarias wrote:

Hello Vincent,
Maybe you can have your header expression outside of the container that have the record list and when using the AJAX refresh, refresh only the record list container.

Best Regards

Hey,


thanks for the quick reply, I in fact tried it but with no success. It still changes and I guess maybe it has to do with the BulkList it self cause when I refresh the Record List the BulkList refreshes itself.

Maybe I can add some code in the action that refreshes the page? I tried a RunJavaScript action but when I click the button my whole page goes blank.


BTW the JavaScript i'm using to do this its the following:

SyntaxEditor Code Snippet

"<script>document.addEventListener('DOMContentLoaded', function(event) {

    document.getElementById('" + BulkList.Id + "').getElementsByTagName('INPUT')[0].setAttribute('title', 'Selecionar todos/nenhum');

});</script>"

maybe there is something in it that causes me this issue,

You guys have any more suggestions?


Thanks for helping,

VC

Solution

Maybe if you try this after the table, in an expression that is also refreshed:

"<script>
    document.getElementById('" + BulkList.Id + "').getElementsByTagName('INPUT')[0].setAttribute('title', 'Selecionar todos/nenhum');
</script>"

Let us know if it worked.

Solution

Just for the record,

If you have a JavaScript that uses a Widget ID, the JavaScript MUST be refreshed at the SAME time that the element it uses the ID. This is necessary because the Ajax will change the Id and if the code is not refreshed in the same ajax (or a subsequent, I think), the JavaScript will stop working as it will have a different ID.

So, if you refresh the List, you HAVE to refresh in the same ajax the script.

Usually we put a "wrapper" (div) around the table AND the JavaScript, and ajax refresh this wrapper.

Cheers,
Eduardo Jauch

Hey guys, 


Sorry for the late answer. 

i was able to solve it by applying the JS that Paulo Zacarias provided me and placing the expression outside the table records. When I refreshed the container that contains both table records and expression It was still showing the title in portuguese.

Thanks a lot guys, I always appreciate your help :)

Cheers

VC