Grid app and JavaScript

I have the following code in a grid application:

onScriptInit:
?>

<script src=’<?php echo sc_url_library(‘prj’, ‘jquery’, ‘jquery-3.3.1.min.js’); ?>’></script>
<script src=’<?php echo sc_url_library(‘prj’, ‘inlinegraph’, ‘jquery.sparkline.min.js’); ?>’></script>

<script>
window.onload=function() {
$(’.inlinesparkline’).sparkline(‘html’, { type: ‘line’, width: ‘150’, height: ‘50’} ) }; </script>

<?

and in: onRecord:

$resultado1= array();

$check_sql = “SELECT resultv2.resultado_num, psoli.id_nbu, prot.no_hc, prot.fec_prot FROM protocol prot INNER JOIN practicas_solicitadas psoli ON prot.no_prot = psoli.no_prot INNER JOIN resultados_v2 resultv2 ON psoli.id_prac_solic_pk = resultv2.id_prac_solic_fk WHERE (psoli.id_nbu = '” . {resultados_v2.id_nbu_fk} . “’) AND (prot.no_hc = '” . {paciente.no_hc} . “’) AND (resultv2.resultado_num > ‘0’) ORDER BY prot.fec_prot”;

sc_select(rs1, $check_sql);
f ({rs1} === false) {
$list_resultado= “1,2”; }
else {
while(!{rs1}->EOF) {
$resultado1[]= {rs1}->fields[0];
{rs1}->MoveNext();
}
{rs1}->Close();
list_resultado= Implode(",", $resultado1); }

{grafico}="<span class=‘inlinesparkline’>" . $list_resultado . “</span>”;

my question is, why the javascript code runs only at the beginning of the grid (look at the graph in the last column, page_1.png) and not in the navigation (page_2.png), thanks for now

page_1.png

page_2.png

Hello everyone, to be more specific about my concern, why javascript functions are only executed when loading the grid and does not run again when I move through the different pages, thanks for now

Just a quick guess - I did not verify this:

I believe, that the grid does not reload the window when going to another page of data. Only a inner part of the DOM (a iframe for example) will load via an AJAX technology.
Therefore your event window_onload will not be executed the second time and so on (will run only the first time).

Sincerely
Gunter Eibl

Dear Gunter Eibl, thanks for your help, I changed the code, removing the javascript function from the onScriptInit event,
and placed that function inside the field in the onRecord event, at the same time activate the option “Run content in Javascript” in that field.
In this way now the code is executed normally when I advance through the registers. Below I detail the new code. Thanks again and regards
Ricardo

$linea=rand();

{grafico}="
<script>
$(function() {
var myvalues = [" . $list_resultado . “];
$(’.dynamicsparkline”.$linea."’).sparkline(myvalues, {
type: ‘line’,
width: ‘100’,
height: ‘25’});

});
</script>

<span class=‘dynamicsparkline".$linea."’></span>";

Hi rcapozza,
I’m happy that it did help you.

And thank you for sharing your final solution!

Gunter Eibl