Using a Snippet to Export to Excel

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I am trying to use a snippet and a custom button to export model data to excel but I have a couple things I am stuck on. I am mainly doing this because I want to export fields that are outside my table but do not want to append the record id. It seems I can't do both point and click.

1. When using a snippet, how do I add custom labels to the fields? Is this possible?

2. When using this method it seems I lose the functionality of selecting which rows I want to export. Is this true? Can you only export all rows?


Here's my sample snippet:

var model = skuid.model.getModel('Estimates');
model.exportData({

  fileName: 'All_Estimates',
  
  usetablecolumns:"false",

  fields: [

      model.getField('Estimate__r.Name'),

      model.getField('Estimate__r.Description__c'),

      model.getField('Estimate__r.Location__r.Name'),

      model.getField('Status__c'),
      
      model.getField('Estimate__r.Status__c')

  ],

  doNotAppendRowIdColumn: true,


});
Photo of Ryan Denis

Ryan Denis

  • 542 Points 500 badge 2x thumb

Posted 3 years ago

  • 1
Photo of JG GBC

JG GBC

  • 694 Points 500 badge 2x thumb
Hi Ryan

Try this:
var $ = skuid.$;

var model = skuid.model.getModel('Estimates'),
TABLE_UNIQUE_ID = 'yourTableId',
list = skuid.$('#'+TABLE_UNIQUE_ID).data('object').list,
selectedRows = skuid.$.map(list.getSelectedItems(),function(item){
return item.row;
});

var estName = model.getField('Estimate__r.Name'),
estDesc = model.getField('Estimate__r.Description__c');
estName.label = 'yourlabel';
estDesc.label = 'yourlabel';

model.exportData({

fileName: 'All_Estimates',

fields: [
estName,
estDesc
],

rows: selectedRows,

doNotAppendRowIdColumn: true,

});
Add the rest of your fields to the code.

This will export all rows, which you selected in the table (Like a mass action).

Hope that helps...
(Edited)
Photo of Ryan Denis

Ryan Denis

  • 542 Points 500 badge 2x thumb
Thank you!