1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
    shaoen01 is on a distinguished road

      0  

    Default Answered: Grid with File Download Link?

    Answered: Grid with File Download Link?


    Hi,

    I am currently using grid with row editor plugin to help update rows to my MySQL database. I would like to add this new feature of uploading files to each row. Has anyone done this before? I am thinking maybe adding a button to open a new window to upload attachments like how we normally do on forums, etc?

    Also, how do i make the file appear as a link on my grid so that when someone clicks on that link, the file prompts you a download window?

    Any suggestions will be great!

  2. Define a renderer in your column model, and then build the link in that render-function.

    E.g.
    Code:
    Ext.define('BII.view.reports.DocumentGrid', {
      extend: 'Ext.grid.Panel',
      alias: 'widget.documentGrid',
      
      initComponent: function () {
        var conf = {
          title: 'Files',
          store: 'Documents',
          forceFit: true
        };
        Ext.apply(this, conf);
        this.columns = this.buildColumns();
        this.callParent(arguments);    
      },
      
      buildColumns: function () {
        return [
          {
            header: 'Type',
            dataIndex: 'extension',
            renderer: this.renderExtension,
            width: 20
          }, 
          {
            header: 'File',
            dataIndex: 'filename',
            flex: 1
          }, 
          {
            header: 'last Change',
            dataIndex: 'lastChange',
            width: 120
          }, 
          {
            header: 'Size',
            dataIndex: 'filesize',
            align: 'right',
            renderer: Ext.util.Format.fileSize,
            width: 100
          }
        ];
      },
      
      renderExtension: function (val, obj, record) {
        return '<a href="data/mod/berichte/getDocument?data=' + record.data.fullpath + '" target="_blank" /><img src="/resources/icons/fatcow/16/page_white_' + val + '.png" /></a>';
      }
    });

  3. #2
    Ext JS Premium Member
    Join Date
    Jan 2008
    Location
    Germany, Berlin
    Posts
    135
    Answers
    21
    Vote Rating
    11
    fschaeffer will become famous soon enough

      0  

    Default


    Define a renderer in your column model, and then build the link in that render-function.

    E.g.
    Code:
    Ext.define('BII.view.reports.DocumentGrid', {
      extend: 'Ext.grid.Panel',
      alias: 'widget.documentGrid',
      
      initComponent: function () {
        var conf = {
          title: 'Files',
          store: 'Documents',
          forceFit: true
        };
        Ext.apply(this, conf);
        this.columns = this.buildColumns();
        this.callParent(arguments);    
      },
      
      buildColumns: function () {
        return [
          {
            header: 'Type',
            dataIndex: 'extension',
            renderer: this.renderExtension,
            width: 20
          }, 
          {
            header: 'File',
            dataIndex: 'filename',
            flex: 1
          }, 
          {
            header: 'last Change',
            dataIndex: 'lastChange',
            width: 120
          }, 
          {
            header: 'Size',
            dataIndex: 'filesize',
            align: 'right',
            renderer: Ext.util.Format.fileSize,
            width: 100
          }
        ];
      },
      
      renderExtension: function (val, obj, record) {
        return '<a href="data/mod/berichte/getDocument?data=' + record.data.fullpath + '" target="_blank" /><img src="/resources/icons/fatcow/16/page_white_' + val + '.png" /></a>';
      }
    });

  4. #3
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
    shaoen01 is on a distinguished road

      0  

    Default


    Thanks for the code. Does this work even if i store the file in my database as blob data type?

  5. #4
    Ext JS Premium Member
    Join Date
    Jan 2008
    Location
    Germany, Berlin
    Posts
    135
    Answers
    21
    Vote Rating
    11
    fschaeffer will become famous soon enough

      0  

    Default


    Hi, it is all a matter of your backend.

    You can link to a URL of your choice, so if you link to a URL which extracts the file from DB and then sends the data via Header information you will be able to get your file from DB ....

    In my example I do exactly the same (I'm reading my file from disk and then send the data via PHP-script to the browser).

    PS: please mark this thread as answered

  6. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
    shaoen01 is on a distinguished road

      0  

    Default


    Hi,

    Yes, you are right! One last thing, is there any file upload tool i can use? So i can put it as part of my form to upload files to my database before clicking on save button to do that? Thanks

  7. #6
    Ext JS Premium Member
    Join Date
    Jan 2008
    Location
    Germany, Berlin
    Posts
    135
    Answers
    21
    Vote Rating
    11
    fschaeffer will become famous soon enough

      0  

    Default


    What do you mean by tool? There is an example in the examples folder for a file upload via ExtJS (including nice styling of form element) which opens the regular file upload dialogue.

    But the file will only be transferred AFTER you click the upload button.

    There might be flash uploader which will upload your files in a more convenient way but I don't know of any for ExtJS.

  8. #7
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
    shaoen01 is on a distinguished road

      0  

    Default


    I might have cause some confusion. By tool i meant plugin like the roweditor, etc. But i will take a look at the example, i didn't notice it was there until you mentioned it. Thanks again.

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."