paginator mazání položek, neinvalidace seznamu

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
Dynab
Člen | 5
+
0
-

Ahoj, mám seznam se stránkováním. Každou položku je možné smazat, položka se správně smaže, problémem je, že se snippet neinvaliduje.

Paginator:

public function actionDefault() {
		$this->businesses = $this->businessRepo->getBusinessesPerPage($this->limit, $this->offset);
		// Get visual paginator components
        $visualPaginator = $this['visualPaginator'];
        // Get paginator form visual paginator
        $this->paginator = $visualPaginator->getPaginator();
        // Define items count per one page
        $this->paginator->itemsPerPage = $this->limit;
        // Define total items in list
		$count = $this->businessRepo->getBusinessCount();
        $this->paginator->itemCount = $count;
        // $this->paginator limits to list

		$that = $this;
        // Define event for example to redraw snippets
        $this['visualPaginator']->onShowPage[] = (function ($component, $page) use ($that) {
			$this->page = $page;
			$this->offset = ($this->page * $this->limit) - $this->limit;
			$this->businesses = $this->businessRepo->getBusinessesPerPage($this->limit, $this->offset);
            if ($that->isAjax()){
                $that->redrawControl('paginator');
            }
        });
	}

public function renderDefault() {
		$this->template->businesses = $this->businesses;
	}

Metoda na mazání:

public function handleDeleteBusiness($businessId) {
		$business = $this->em->find(Business::class, $businessId);
		if (!is_null($business)) {
			$this->em->remove($business);
			$this->em->flush();
		}
	//	$this->paginator->setPage($this->paginator->getPage());
	//	$this->redirect('this');
		if ($this->isAjax()) {
			$this->offset = ($this->paginator->page * $this->limit) - $this->limit;
			$this->businesses = $this->businessRepo->getBusinessesPerPage($this->limit, $this->offset);
            $this->redrawControl('paginator');
			$this->payload->businessId = $businessId;
			$this->sendPayload();
		}
	}

Šablona:

<!-- Widget Row Start grid -->
	{snippet paginator}
       <div class="row" id="powerwidgets">
         <div class="col-md-12 bootstrap-grid">

           <!-- New widget -->
           <div class="powerwidget dark-blue" id="forum" data-widget-editbutton="false">
             <header>
		  <strong class="business-header">Podniky</strong>
             </header>
             <div class="inner-spacer">
		{foreach $businesses as $business}
               <div class="forum">
                 <ul>
                   <li>
                     <div class="col-lg-8 col-md-6 col-sm-8">
                       <div class="main-details"> <i class="fa fa-comments"></i>
                         <h3>{$business->name}</h3>
                         <span class="description">{$business->description}</span> </div>
                     </div>
                     <div class="col-lg-2 col-md-3 visible-lg visible-md">
                       <div class="nums-container">
                         <ul class="nums">
                           <li><strong>Zeměpisná šířka:</strong> {$business->lat}</li>
                           <li><strong>Zeměpisná výška</strong> {$business->lng}</li>
                         </ul>
                       </div>
                     </div>
			  <div class="col-lg-2 col-md-3 col-sm-5 hidden-xs">
			      <span class="last-post"><a n:href="Business:edit $business->id">Editovat podnik</a></span>
			      <span class="last-post"><a n:href="Filters: $business->id">Editovat filtry</a></span>
			      <span class="last-post"><a href="#" class="confirm" data-toggle="modal" data-target="#modal-{$business->id}">Smazat</a></span>
			  </div>
                     <div class="clearfix"></div>
                   </li>
                 </ul>
               </div>


		<!-- Modal -->
		<div id="modal-{$business->id}" class="modal fade" role="dialog">
		  <div class="modal-dialog">

		    <!-- Modal content-->
		    <div class="modal-content">
		      <div class="modal-header">
			<button type="button" class="close" data-dismiss="modal">&times;</button>
			<h4 class="modal-title">Smazání podniku {$business->name}</h4>
		      </div>
		      <div class="modal-body">
			<p>Jste si jistý?</p>
		      </div>
		      <div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Zpět</button>
			<a type="button" class="btn btn-primary ajax" n:href="deleteBusiness! $business->id">Smazat</a>
		      </div>
		    </div>
		  </div>
		</div>
	    {/foreach}
             </div>
           </div>
	  </div>
	</div>
	      {control visualPaginator}
	      {/snippet}
David Matějka
Moderator | 6445
+
+1
-

smaz sendPayload. to ukonci beh presenteru a nedostane se k provadeni sablony (az tam dochazi k fakticke invalidaci snippetu)

Dynab
Člen | 5
+
0
-

ano to funguje, díky