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

Notice: This thread is very old.
Pavel Janda
Member | 977
+
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)

David Matějka
Moderator | 6445
+
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>
Pavel Janda
Member | 977
+
0
-

That works perfectly, thank's a lot!

Pavel Janda
Member | 977
+
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)