Filtrovaní tabulky přes textové pole pomocí AJAXem
- Azim
- Člen | 41
Zdravim. Potrebuju filtrovat data v tabulce pomoci textoveho pole, ktere okamzite po zadani znaku vyfiltruje data podle toho, zda odpovidaji zadanemu znaku/retezci.
ProjectPresenter vypada takto
<?php
class ProjectPresenter extends SecuredPresenter
{
public function renderDefault()
{
$this->template->projects = $this->model->getProjects();
}
public function createComponentProjectForm($name)
{
$form = new AppForm($this, $name);
$form->addText('Name', 'Name');
$form->addText('Description', 'Description');
$form->addText('SAP_ID', 'SAP ID');
$form->addText('KeyCode', 'Key Code');
$form->addText('PO', 'PO');
$form->addText('PIPM', 'PIPM');
$form->addText('TM', 'TM');
$form->addText('PMOE', 'PMOE');
$form->addText('PPaC', 'PP&C');
$form->addSelect('PMO', 'PMO support level', array('*', 'Full', 'Basic'));
$form->addSelect('Phase', 'Project phase', array('*', 'Active', 'Planned', 'Closed'));
$form->addSelect('Type', 'Project type', array('*', 'B&P', 'Internal', 'External', 'Capital'));
$tmp = $this->model->getCustomers();
$customers = array('*' => '*');
foreach ($tmp as $customer)
{
$customers[$customer->Customer_ID] = $customer->Name;
}
$form->addSelect('Customer', 'Customer', $customers);
$tmp = $this->model->getResponsibilities();
$responsibilities = array('*' => '*');
foreach ($tmp as $responsibility)
{
$responsibilities[$responsibility->Responsibility_ID] = $responsibility->Name;
}
$form->addSelect('Responsibility', 'Responsibility', $responsibilities);
$form->addText('Start', 'Start date');
$form->addText('End', 'End date');
$form->addText('TotalBudget', 'Budget');
$tmp = $this->model->getStates();
$states = array('*' => '*');
foreach ($tmp as $state)
{
$states[$state->Number] = $state->Number.': '.$state->Name;
}
$form->addSelect('State', 'State', $states);
}
}
?>
sablona pro vykreslovani
{block #content}
Project Presenter
{widget projectForm}
<table>
<tr>
<th>Project_ID</th>
<th>Name</th>
<th>SAP_ID</th>
<th>Description</th>
<th>PIPM</th>
<th>TM</th>
<th>PMOE</th>
<th>PPaC</th>
<th>Date</th>
<th>State</th>
</tr>
{snippet projects}
{foreach $projects as $project}
<tr>
<td>{$project->Project_ID}</td>
<td>{$project->Name}</td>
<td>{$project->SAP_ID}</td>
<td>{$project->Description}</td>
<td>{$project->PIPM}</td>
<td>{$project->TM}</td>
<td>{$project->PMOE}</td>
<td>{$project->PPaC}</td>
<td>{$project->Date}</td>
<td>{$project->State}</td>
</tr>
{/foreach}
{/snippet}
</table>
Vim, ze je potreba zapojit AJAX, akorat nevim jak se pohnout z mista,
potrebuju nakopnout. Nekdo nejake rady?
Diky moc.
- bojovyletoun
- Člen | 667
- do presenteru bych přidal persistentní proměnnou nazvanou
pattern
. - V render metodě bych udělal zhruba tohle
if($this->pattern)$model->where('jmeno=%s',$this->pattern);
- pak bych na stránku přidělal formulář, který by po odeslání nastavil $this->pattern na zadanou hodnou.
- Osobně jsem si vytvořil pro formulářové prvky, které se mají měnit(já to používám na selectbox) při pouhé změně třídu quick.
- soubor s obshluhou nette ajaxu a formů má tedy tuto část:
$(".quick").live("change", function (event) {
event.preventDefault();
$(this).closest('form').ajaxSubmit();
return false;
});