Articles in this section
Category / Section

How to change the default file name in JavaScript Spreadsheet?

1 min read

This knowledge base explains how to change the default file name in JavaScript Spreadsheet Save As dialog. To achieve this requirement, you can use the spreadsheet dialogBeforeOpen event and change the value of the input element in the dialog component open event.

[HTML]

<div id="spreadsheet"></div> 

[TS]

import { getComponent } from '@syncfusion/ej2-base';
import {
 DialogBeforeOpenEventArgs,
 Spreadsheet,
} from '@syncfusion/ej2-spreadsheet';
import { Dialog as DialogComponent } from '@syncfusion/ej2-popups';

function beforeOpen(): void {
 //Get the input element and customize the value.
 let element: HTMLInputElement = this.element.getElementsByClassName(
   'e-text-open'
 )[0] as HTMLInputElement;
 element.value = 'Your Own Text';
}

let spreadsheet: Spreadsheet = new Spreadsheet({
 openUrl: 'https://services.syncfusion.com/js/production/api/spreadsheet/open',
 saveUrl: 'https://services.syncfusion.com/js/production/api/spreadsheet/save',
 dialogBeforeOpen: (args: DialogBeforeOpenEventArgs): void => {
   //Get instance of the Save As dialog by checking the dialog name.
   if (args.dialogName === 'Save As') {
     let dlg: DialogComponent = getComponent(
       spreadsheet.element.querySelector('.e-dialog') as HTMLElement,
       'dialog'
     );
     dlg.open = beforeOpen;
   }
 },
});

spreadsheet.appendTo('#spreadsheet');

Sample Link:

https://stackblitz.com/edit/8fsxwh-acj92e?file=index.ts

Output:

Change_default_sample_name.gif

Documentation link:

https://ej2.syncfusion.com/documentation/spreadsheet/open-save

https://ej2.syncfusion.com/documentation/dialog/getting-started

Conclusion

​I hope you enjoyed learning about how to change the default file name in JavaScript Spreadsheet.

You can refer to our JavaScript Spreadsheet feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Spreadsheet example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied