Agile toolkit : how to automatically reload grid

2019-07-11 03:49发布

Using Agile toolkit to generate a grid, I'm trying to get an automatic reload of a grid but I can't figure how :/

I dug into the js() function and saw the first parameter is $when but, how to set up an interval?

Reload on event like button click is ok, but I need to set up reload every x sec.

2条回答
贪生不怕死
2楼-- · 2019-07-11 04:40

OK here is complete tested example how you should do.

First I have to admit, that ATK4 had no setInterval and clearInterval functions added in univ() library, but already had setTimeout. I added setInterval and clearInterval and made pull request in Github (https://github.com/atk4/atk4/pull/173). I hope Romans will accept that, but if not, then you can always add these functions in your own JS library.

So here is the code:

$g = $this->add('Grid');
$this->js(true)->univ()->setInterval(
    $g->js()->reload()->_enclose()
,3000);

Or you can even execute multiple independent functions like this:

$this->js(true)->univ()->setInterval(
    $g->js(null,array(
        $g->js()->reload(),
        $g->js()->univ()->successMessage('Reloaded...')
    ))->_enclose()
,3000);

Key part here is ->_enclose() method which will convert your JS chain to anonymous JS function.

查看更多
Melony?
3楼-- · 2019-07-11 04:51

Javascript code :

setInterval("func()",1000);

This will call the func() function every 1000 ms

查看更多
登录 后发表回答