• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Date format sent to backend grid vs. download

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Date format sent to backend grid vs. download

    I have an application I designed with a Sencha Architect front end and RPG backend. It has a grid displaying records, and the user can select a FROM and TO date from the drop-down calendar to limit the records selected. This works fine for display.

    BUT, clicking the download button produces an empty Excel file. Comparing the two requests being made, I see that the format of the dates is different when just displaying the grid vs. requesting a download. When doing the download, the date format is incorrect and no data is selected, resulting in the empty Excel file.

    Request when displaying the grid:

    V_Grid.JPG
    This one above that is sent when in the grid works correctly in the SQL statement on the back end and returns the correct records.

    Request when clicking the download button:

    V_Download.JPG

    This second one that is sent when doing the download does not work correctly in the SQL statement on the back end and therefore no records are returned in the resulting Excel file.

    How to fix? Thanks!

  • #2
    Hi,

    Looks like your method of "onDownloadButtonClick" is adding fromdate/todate with the javascript date object value instead of the formatted timestamp

    I would search your front-end source for fromdate and/or todate outside of the method "onDownloadButtonClick" on how it's passing down the values for both those params.

    Then do the same in "onDownloadButtonClick"

    Thanks

    Comment


    • #3
      Could you post the JavaScript code that gets run when the download button is clicked? I can look at that code and adjust it for you so that the dates are formatted correctly.

      Comment


      • #4
        OnDownloadButtonClick:

        Code:
        // create a blank object for params
        var d = {
        download: true
        };
        
        // get the store
        var mainstore = Ext.ComponentQuery.query('#filegrid')[0].getStore();
        
        // apply parms from the last call to the store
        Ext.apply(d, mainstore.lastOptions.params);
        
        // apply the default extraparms
        Ext.apply(d, mainstore.getProxy().extraParams);
        
        // apply paging toolbar parms
        d.page = mainstore.lastOptions.page;
        d.start = mainstore.lastOptions.start;
        d.limit = mainstore.lastOptions.limit;
        
        // apply sorters
        d.sort = [];
        d.sort[0] = {
        direction: mainstore.lastOptions.sorters[0].direction,
        property: mainstore.lastOptions.sorters[0].property
        };
        d.sort = Ext.encode(d.sort);
        
        // add the download parm
        d.download = true;
        
        // call the download
        Valence.util.download(d);
        Here is the proxy:

        Code:
        proxy: {
        type: 'ajax',
        extraParams: {
        pgm: 'VXECPAY',
        action: 'getRecs',
        showopenonly: 'true',
        fromdate: '2021-01-01',
        todate: '2021-12-31'
        },
        url: '/valence/vvcall.pgm',
        reader: {
        type: 'json',
        root: 'recs',
        totalProperty: 'totalCount'
        }
        }

        Comment


        • #5
          Below is the suggested update to your OnDownloadButtonClick method based on your original forum post that included your XHR request params for the grid load/download

          Code:
          // create a blank object for params
          var d = {
              download: true
          },
          formatDateToTimestamp = function (prop) {
              var value = d[prop];
              if (!Valence.isEmpty(value) && Valence.isDate(value)) {
                  return Ext.Date.format(value, 'Y-m-d') + 'T00:00:00';
              }
              return value;
          };
          
          // get the store
          var mainstore = Ext.ComponentQuery.query('#filegrid')[0].getStore();
          
          // apply parms from the last call to the store
          Ext.apply(d, mainstore.lastOptions.params);
          
          // apply the default extraparms
          Ext.apply(d, mainstore.getProxy().extraParams);
          
          // apply paging toolbar parms
          d.page = mainstore.lastOptions.page;
          d.start = mainstore.lastOptions.start;
          d.limit = mainstore.lastOptions.limit;
          
          // apply sorters
          d.sort = [];
          d.sort[0] = {
              direction: mainstore.lastOptions.sorters[0].direction,
              property: mainstore.lastOptions.sorters[0].property
          };
          d.sort = Ext.encode(d.sort);
          
          // add the download parm
          d.download = true;
          
          // format the from/to dates to timestamps
          //
          d.fromdate = formatDateToTimestamp('fromdate');
          d.todate = formatDateToTimestamp('todate');
          
          // call the download
          Valence.util.download(d);
          Whats changed:
          • Added new function "formatDateToTimestamp
          • Before Valence.util.download if fromdate/todate exists and is a date object format it to a timestamp
          Documentation on formatting date objects
          Last edited by Johnny Major; 01-08-2021, 09:57 AM.

          Comment


          • #6
            That worked - thanks!

            Comment

            Working...
            X