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

Re: Server-driving DataTable with Filter

Expand Messages
  • nanabite
    Hi Luke, Perfect! I implemented a generateRequest method as well as the delay for my filter. My event handler: var filterTimeout = null;
    Message 1 of 3 , Feb 4, 2009
      Hi Luke,

      Perfect! I implemented a generateRequest method as well as the delay for my filter.

      My event handler:

      var filterTimeout = null;
      YAHOO.util.Event.on('name_input', 'keyup', function (e) {
          clearTimeout(filterTimeout);
          setTimeout(updateFilters, 600);
      });

      My method to update the DataSource and DataTable:

      var updateFilters = function(event) {
          nameFilter = YAHOO.util.Dom.get('name_input').value;
         
          var oCallback = {
              success: function (oRequest, oResponse, oPayload) {
                  myDataTable.onDataReturnInitializeTable(oRequest, oResponse, oPayload);
                  myPaginator.set('totalRecords', oResponse.meta.totalRecords);
              },
              failure: function (oRequest, oResponse, oPayload) {
                   alert('Failed to connect to server');
              },
              scope: myDataTable,
              argument: ""
          }
         
          myDataSource.sendRequest(generateRequest(null, myDataTable), oCallback);
      };


      Thanks so much for the assistance :)

      Adam

      --- In ydn-javascript@yahoogroups.com, "Lucas Smith" <lsmith@...> wrote:
      >
      > Adam,
      >
      > This looks like a case for specifying the generateRequest configuration.
      > function genReq(state, dt) {
      > // Set defaults
      > state = state || {pagination:null, sortedBy:null};
      >
      > var sort = (state.sortedBy) ? state.sortedBy.key :
      > dt.getColumnSet().keys[0].getKey(),
      > dir = (state.sortedBy && state.sortedBy.dir ===
      > YAHOO.widget.DataTable.CLASS_DESC) ? "desc" : "asc",
      > startIndex = (state.pagination) ? state.pagination.recordOffset
      > : 0,
      > results = (state.pagination) ? state.pagination.rowsPerPage :
      > null,
      > filter =
      > encodeURIComponent(YAHOO.util.Dom.get('name_input').value);
      >
      > // Build the request
      > return "filter=" + filter +
      > "sort=" + sort +
      > "&dir=" + dir +
      > "&startIndex=" + startIndex +
      > ((results !== null) ? "&results=" + results : "");
      > }
      >
      > var tbl_config = {
      > ...
      > generateRequest : genReq
      > };
      >
      > var myDataTable = new DataTable(el, cols, myDataSource, tbl_config);
      >
      > Also, have a look at this example for delaying the filtering a bit from
      > key events to avoid excessive server io while the user is typing the
      > filter value:
      > http://yuiblog.com/sandbox/yui/v260/examples/datatable/filtered.html
      >
      > Hope this helps,
      > Luke
    Your message has been successfully submitted and would be delivered to recipients shortly.