Skip to content

Commit 30201ce

Browse files
authored
Merge pull request #39 from soumayatcm/5.2
Add custom loader to EvoluGrid
2 parents 8e673fe + 2753670 commit 30201ce

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

doc/evolugrid_php.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ $evoluGrid->setId('myGridId'); // Set the HTML ID of the grid
3737
$evoluGrid->setClass('table'); // Set the CSS class of the grid
3838
$evoluGrid->setExportCSV(true); // Whether CSV export is available
3939
$evoluGrid->setInfiniteScroll(true); // Whether to use infinite scroll or pagination
40+
$evoluGrid->setCustomLoader(new HtmlString('<div class="my_loader"></div>')); // Set a custom loader
4041

4142
// Outputs the HTML and Javascript to display the grid.
4243
$evoluGrid->toHtml();

js/evolugrid.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,7 @@
216216
var descriptor = $.extend(true, {}, defaultOptions, options);
217217
return this.each(function(){
218218
$(this).data('descriptor', descriptor);
219-
220219
var $this = $(this);
221-
222220
if (descriptor.infiniteScroll) {
223221
// We initialise the infinite scroll
224222
scrollReady = true;
@@ -355,6 +353,7 @@
355353
}
356354
} else {
357355
$this.next('div.ajaxLoader').hide();
356+
358357
}
359358
});
360359
},
@@ -594,7 +593,6 @@
594593
$(descriptor.filterForm).find("button").attr("disabled", false);
595594
$(descriptor.filterForm).find("input[type=button]").attr("disabled", false);
596595
}
597-
598596
//We hide the ajax loader
599597
$this.next('div.ajaxLoader').hide();
600598

@@ -766,7 +764,7 @@
766764

767765
//set additionnal data
768766
additionnalData = data.additionnalData;
769-
767+
770768
//We hide the ajax loader
771769
$this.next('div.ajaxLoader').hide();
772770

src/Mouf/Html/Widgets/EvoluGrid/EvoluGrid.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ class EvoluGrid implements HtmlElementInterface
141141
*/
142142
private $chevronDownClass;
143143

144+
/**
145+
* If the customLoader is set, this property allows setting a custom loader
146+
*
147+
* @var HtmlElementInterface
148+
*/
149+
private $customLoader;
150+
144151
/**
145152
* Message to display if no results are shown.
146153
*
@@ -385,6 +392,19 @@ public function setRowEventListeners($rowEventListeners)
385392
return $this;
386393
}
387394

395+
/**
396+
* An object generating HTML for the loader.
397+
*
398+
* The generated HTML MUST use
399+
*
400+
* @param HtmlElementInterface $customLoader
401+
* @return $this
402+
*/
403+
public function setCustomLoader($customLoader) {
404+
$this->customLoader = $customLoader;
405+
return $this;
406+
}
407+
388408
/**
389409
* @param string $onResultShown
390410
*/
@@ -512,12 +532,20 @@ public function toHtml()
512532
}
513533
echo '
514534
<div id="'.$id.'"></div>';
515-
if ($this->infiniteScroll) {
516-
echo '<div class="ajaxLoader" style="text-align: center; margin-top: 20px; margin-bottom: 20px; display: none;"><img src="'.ROOT_URL.'vendor/mouf/html.widgets.evolugrid/img/ajax-loader.gif" alt="ajax-loader"></div>';
535+
536+
/** if the customLoader is set we use it instead of the default one **/
537+
if ($this->customLoader) {
538+
echo '<div class="ajaxLoader">';
539+
$this->customLoader->toHtml();
540+
echo '</div>';
517541
} else {
518-
echo '<div class="ajaxLoader" style="text-align: center; background-color: black; width: 100%; height: 100%; position: absolute; top: 0; opacity: 0.3"><img src="'.ROOT_URL.'vendor/mouf/html.widgets.evolugrid/img/ajax-loader.gif" alt="ajax-loader" style="margin-top: -20px; position: absolute; top: 50%;"></div>';
542+
if ($this->infiniteScroll) {
543+
echo '<div class="ajaxLoader" style="text-align: center; margin-top: 20px; margin-bottom: 20px; display: none;"><img src="'.ROOT_URL.'vendor/mouf/html.widgets.evolugrid/img/ajax-loader.gif" alt="ajax-loader"></div>';
544+
} else {
545+
echo '<div class="ajaxLoader" style="text-align: center; background-color: black; width: 100%; height: 100%; position: absolute; top: 0; opacity: 0.3"><img src="'.ROOT_URL.'vendor/mouf/html.widgets.evolugrid/img/ajax-loader.gif" alt="ajax-loader" style="margin-top: -20px; position: absolute; top: 50%;"></div>';
546+
}
519547
}
520-
echo '</div>
548+
echo '</div>
521549
<script type="text/javascript">
522550
(function($) {
523551
$(document).ready(function() {

0 commit comments

Comments
 (0)