Loading ...
Sorry, an error occurred while loading the content.

Re: [ydn-javascript] implementing simple search using DataTable & Paginato

Expand Messages
  • Pawel Sokolowski
    You need to update the paginator with the new total row count in your success callback function. Something like that : var oCallback = { success: function(req,
    Message 1 of 2 , Jan 29, 2009
    • 0 Attachment
      You need to update the paginator with the new total row count in your success callback function. Something like that :

      var oCallback = {
      success: function(req, res, payload) {
                  this.get('paginator').set('totalRecords', res.results.length);
                  this.onDataReturnReplaceRows.apply(this, arguments);
      },
      failure: function (oRequest,oResponse,oPayload) {
      alert('Failed to connect to server.');
      },
      scope: dataTable,
      argument: ""
      }


      Hope it helps, 

      Pawel 


      On Thu, Jan 29, 2009 at 4:02 PM, alexander.glass <alexander.glass@...> wrote:

      I've spent about 4 hours digging through the docs and searching online
      but can't seem to figure out this simple problem. I have a datatable
      that implements server side pagination and sorting. Now I need a
      search box and a button to filter through the datatable results. The
      problem is that while the search returns my records - I cannot get the
      paginator to refresh properly. Maybe someone could spare me from
      having to create a custom paginator. Below is a relevant code
      snippet. Thanks for any support.

      ######################################################################
      YAHOO.util.Event.addListener(window, "load", function() {
      var dataTable = null, dataSource = null;

      var f = document.forms[0];

      YAHOO.util.Event.addListener(f.btnSearch, "click", function() {
      var title = escape(f.title.value);

      var oCallback = {
      success: dataTable.onDataReturnReplaceRows,
      failure: function (oRequest,oResponse,oPayload) {
      alert('Failed to connect to server.');
      },
      scope: dataTable,
      argument: ""
      }

      dataTable.showTableMessage(YAHOO.widget.DataTable.MSG_LOADING,
      YAHOO.widget.DataTable.CLASS_LOADING);
      dataSource.sendRequest('title='+title, oCallback);
      });

      var cols = [ {key:"id"}, {key:"name"} ];

      dataSource = new YAHOO.util.DataSource("searchSvr.php?");
      dataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
      dataSource.connXhrMode = "queueRequests";
      dataSource.responseSchema = {
      resultsList: "data",
      fields: ["id","name"],
      metaFields: { totalRecords: "totalRecords"}
      };

      var cfg = {
      paginator: new YAHOO.widget.Paginator({rowsPerPage: 50}),
      dynamicData: true
      };

      dataTable = new YAHOO.widget.DataTable("ytable", cols,
      dataSource, cfg);
      }); // end addListener


    Your message has been successfully submitted and would be delivered to recipients shortly.