Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client-side/twigrid.datagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,15 @@ $.nette.ext({
});
}

//update active row
if (payload.twiGrid !== undefined && payload.twiGrid.iePrimary !== undefined) {
$.each(payload.twiGrid.iePrimary, function (form, iePrimary) {
var formEl = $('#' + form);
formEl.find(".inline-edit-row").removeClass("inline-edit-row").removeClass("success");
formEl.find("tr[data-primarystring='"+iePrimary+"']").addClass("inline-edit-row").addClass("success");
});
}

// scroll to first flash message
var flash = $(this.flashSelector);
if (flash.length) {
Expand Down
53 changes: 34 additions & 19 deletions src/TwiGrid/DataGrid.latte
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
{/ifset}
{/foreach}

<th class="header-cell" n:if="$hasFilters || $hasRowActions || $hasInlineEdit">&nbsp;</th>
<th class="header-cell header-actions-cell" n:if="$hasFilters || $hasRowActions || $hasInlineEdit">&nbsp;</th>
</tr>

{/define}
Expand Down Expand Up @@ -215,10 +215,39 @@

{if}{? $grid->addGroupActionCheckboxes(); $grid->addInlineEditControls() }

{foreach $dataLoader() as $record}
{foreach $data as $record}
{var $primaryString = $template->primaryToString($record),
$isInlineEdited = $hasInlineEdit && $iePrimary === $primaryString}
{var $params = [
record => $record,
iterator => $iterator
]}
{if $redrawWholeBody}
<tr n:class="$isInlineEdited ? success" data-primarystring="{$primaryString}" id="{$_control->getSnippetId("row-$primaryString")}">
{include #row-content, (expand) $params}
</tr>
{else}
<tr n:class="$isInlineEdited ? success" data-primarystring="{$primaryString}" n:snippet="row-$primaryString">
{include #row-content, (expand) $params}
</tr>
{/if}
{/foreach}

{var $template->hasData = (bool) $iterations}

{else}
<tr class="warning">
<td class="body-cell" colspan="{$columnCount}">{_'No data.'}</td>
</tr>
{/if $iterations}

</tbody>

{/define}

{define row-content}
{var $primaryString = $template->primaryToString($record),
$isInlineEdited = $hasInlineEdit && $iePrimary === $primaryString}
<tr n:class="$isInlineEdited ? success">

<td class="body-cell center" n:if="$hasGroupActions">
{var $inputKey = $iterator->counter - 1}
Expand Down Expand Up @@ -247,28 +276,14 @@
{/if}
{/foreach}

<td n:if="$hasFilters || $hasRowActions || $hasInlineEdit" class="body-cell center">
<td n:if="$hasFilters || $hasRowActions || $hasInlineEdit" class="body-cell body-actions-cell center">
{if $hasRowActions || $hasInlineEdit}
{include #row-actions, i => $iterator->counter - 1, record => $record, isInlineEdited => $isInlineEdited, primaryString => $primaryString |indent:3}

{else}
&nbsp;
{/if}
</td>

</tr>
{/foreach}

{var $template->hasData = (bool) $iterations}

{else}
<tr class="warning">
<td class="body-cell" colspan="{$columnCount}">{_'No data.'}</td>
</tr>
{/if $iterations}

</tbody>

{/define}


Expand Down Expand Up @@ -300,7 +315,7 @@
{include #inline-buttons |indent:1}

{else}
{ifset $form[$buttonName = "inline-buttons-$i"]}
{ifset $form[$buttonName = "inline-buttons-$primaryString"]}
{? }{input $buttonName, class => 'btn btn-primary btn-sm'}
{/ifset}

Expand Down
42 changes: 36 additions & 6 deletions src/TwiGrid/DataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class DataGrid extends Nette\Application\UI\Control
/** @var \Closure */
private $ieProcessCallback = NULL;

/** @var array */
private $redrawRows = array();

// === pagination ===========

Expand Down Expand Up @@ -583,22 +585,29 @@ function setInlineEditing($containerCb, $processCb)
*/
protected function activateInlineEditing($primary)
{
$this->redrawRow($this->iePrimary);
$this->redrawRow($primary);
$this->iePrimary = $primary;
$this->refreshState(FALSE);
$this->redraw(FALSE, TRUE, 'body');
$this->redraw(FALSE, TRUE, "body");
}


/**
* @param bool $dataAsWell
* @return void
*/
protected function deactivateInlineEditing($dataAsWell = TRUE)
protected function deactivateInlineEditing($primary, $dataAsWell = TRUE)
{
$this->redrawRow($primary);
$this->refreshState();
$this->redraw($dataAsWell, TRUE, 'body');
}

protected function redrawRow($primary) {
$this->redrawRows[] = $primary;
}


// === PAGINATION ======================================================

Expand Down Expand Up @@ -811,11 +820,11 @@ function processForm(Forms\Form $form)
if ($name === 'edit') {
if (($values = $form->getInlineValues()) !== NULL) {
NCallback::invoke($this->ieProcessCallback, Helpers::findRecord($this->getData(), $this->iePrimary, $this->getRecord()), $values);
$this->deactivateInlineEditing();
$this->deactivateInlineEditing($this->iePrimary);
}

} elseif ($name === 'cancel') {
$this->deactivateInlineEditing(FALSE);
$this->deactivateInlineEditing($this->iePrimary, FALSE);

} else {
$this->activateInlineEditing($button->primary);
Expand Down Expand Up @@ -848,6 +857,15 @@ protected function passForm()
|| $this->isControlInvalid('footer');
}

private function getRedrawRows($data) {
$redrawRows = array();
foreach($data as $record) {
if(in_array($this->getRecord()->primaryToString($record), $this->redrawRows)) {
$redrawRows[] = $record;
}
}
return $redrawRows;
}

/** @return void */
function render()
Expand All @@ -868,10 +886,22 @@ function render()
});

$this->isControlInvalid() && $this->redraw(FALSE, 'flashes');
$this->passForm() && ($template->form = $template->_form = $form = $this['form'])
($template->form = $template->_form = $form = $this['form'])
&& $this->presenter->payload->twiGrid['forms'][$form->elementPrototype->id] = (string) $form->getAction();
$this->presenter->payload->twiGrid['iePrimary'][$form->elementPrototype->id] = $this->iePrimary;
$template->columns = $this->getColumns();
$template->dataLoader = $this->getData;

$data = $this->getData();
$template->data = $data;
$template->redrawWholeBody = true;
if($this->getPresenter()->isAjax() && !empty($this->redrawRows)) {
$redrawData = $this->getRedrawRows($data);
if (count($redrawData) > 0) {
$template->data = $redrawData;
$template->redrawWholeBody = false;
}
}

$template->csrfToken = Helpers::getCsrfToken($this->session, $this->sessNamespace);
$template->rowActions = $this->getRowActions();
$template->hasRowActions = $template->rowActions !== NULL;
Expand Down