redrawControl → all dynamic snippets in one big snippet or the big one

Notice: This thread is very old.

4 years ago

Pavel Janda
Backer | 877
+
0
-

Hi,

here is my template:

<table>
	<thead>
		<!-- never redraw thead! -->
	</thead>
	<tbody n:snippet="data">
		{foreach $items as $item}
			<tr n:snippet="data-{$item->id}">
				<td>

				</td>
			</tr>
		{/foreach}
	</tbody>
</table>

Now, sometimes, i would like to redraw only one row:

$this->template->items[10] = $item;
$this->redrawControl('data');

And sometimes i would like to redraw the whole tbody with different items. That won't work, because Nette is invalidating separately the items.

Is there a way to decide whether to send the big data snippet or the dynamic data-{$id} snippets?

It would work if i add another snippet around the <tbody> tag, but that is not possible due to html validity restrictions.

Last edited by Pavel Janda (2016-01-14 13:38)

4 years ago

David Matějka
Moderator | 5990
+
0
-

I think you can use snippetArea macro as a dynamic snippet wrapper and then use <tbody n:snippet as a “big” snippet:

<table>
    <thead>
        <!-- never redraw thead! -->
    </thead>
    <tbody n:snippet="dataWrapper">
		{snippetArea data}
	        {foreach $items as $item}
    	        <tr n:snippet="data-{$item->id}">
            	    <td>

        	        </td>
    	        </tr>
	        {/foreach}
		{/snippetArea}
    </tbody>
</table>

4 years ago

Pavel Janda
Backer | 877
+
0
-

That works perfectly, thank's a lot!

4 years ago

Pavel Janda
Backer | 877
+
0
-

Well, it solved a problem, but caused another. Sometimes, i am including a template in that tr > td. So when i do that:

$this->template->items[10] = $item;
$this->redrawControl('items');

Nette only sends data that are not in included template.. So there was originally a text “Hello” in included template and after redraw should be there “World”, there is nothing. Nette ignores the included template.

Any perfect idea? :)

Last edited by Pavel Janda (2016-01-14 16:21)