diff mbox

[23/51] dynatable: Allow the user to have a pre-defined per-page element

Message ID 1441986924-26689-24-git-send-email-damien.lespiau@intel.com
State Superseded
Headers show

Commit Message

Damien Lespiau Sept. 11, 2015, 3:54 p.m. UTC
Sometimes users of dynatable don't want the library to generate its own
elements, but use the ones already present in the page.

This patch adds support to do just that for the per-page element.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 lib/packages/jquery/jquery.dynatable.js | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/lib/packages/jquery/jquery.dynatable.js b/lib/packages/jquery/jquery.dynatable.js
index 9285e1e..eb8065d 100644
--- a/lib/packages/jquery/jquery.dynatable.js
+++ b/lib/packages/jquery/jquery.dynatable.js
@@ -1300,7 +1300,8 @@ 
   };
 
   function PaginationPerPage(obj, settings) {
-    var _this = this;
+    var _this = this,
+        fromUser = true;
 
     this.initOnLoad = function() {
       return settings.features.paginate;
@@ -1326,10 +1327,15 @@ 
     };
 
     this.create = function() {
-      var $select = $('<select>', {
+      var $select = $('#dynatable-per-page-' + obj.element.id);
+
+      if (!$select.length) {
+        fromUser = false;
+        $select = $('<select>', {
             id: 'dynatable-per-page-' + obj.element.id,
             'class': 'dynatable-per-page-select'
-          });
+        });
+      }
 
       for (var i = 0, len = settings.dataset.perPageOptions.length; i < len; i++) {
         var number = settings.dataset.perPageOptions[i],
@@ -1342,14 +1348,22 @@ 
         obj.process();
       });
 
+      if (fromUser)
+        return $select;
+
       return $('<span />', {
         'class': 'dynatable-per-page'
       }).append("<span class='dynatable-per-page-label'>" + settings.inputs.perPageText + "</span>").append($select);
     };
 
     this.attach = function() {
+      var element = this.create();
+
+      if (fromUser)
+        return;
+
       var $target = settings.inputs.perPageTarget ? $(settings.inputs.perPageTarget) : obj.$element;
-      $target[settings.inputs.perPagePlacement](this.create());
+      $target[settings.inputs.perPagePlacement](element);
     };
 
     this.set = function(number, skipResetPage) {