Skip to content

JSON and XML export, text tables ​

The api that withExport(api) extends also gets JSON, XML and text-table methods besides CSV, Excel and PDF (1.4.0). Installation and withExport are the same as in CSV, Excel and PDF export. Reading data in is covered in Import and load from a URL.

ts
import { withExport } from '@maxgrid/export';

const ex = withExport(api);
const json = ex.exportJson({ pretty: true });
const xml = ex.exportXml({ rowTag: 'person' });
const table = ex.getTextTable({ header: true });
await ex.downloadJson('people.json');

Methods ​

MethodReturns
exportJson(options?)JSON text: an array of objects keyed by column id
downloadJson(filename?, options?)Saves a JSON file (browser); default name export.json
exportXml(options?)XML text
downloadXml(filename?, options?)Saves an XML file (browser); default name export.xml
getTextTable(options?)A 2-D array of strings (string[][])

Common options ​

OptionValueDefaultEffect
scope'visible' · 'all' · 'selected''visible'Row range; visible rows follow sort and filter, selected rows keep screen order
includeHiddenbooleanfalseAlso includes hidden columns
columnsarray of column idsvisible onesColumns and their order; an unknown id is an invalid-option
text'value' · 'shown''value' for JSON and XML, 'shown' for the text tablevalue is the stored value, shown the displayed text (formatValue, optionLabel)
sanitizeFormulasbooleanfalsePuts ' in front of text that starts with =, +, -, @ or a tab
locale'ko' · 'en' …grid localeLanguage of error messages

Rows that are only marked as removed (removeMode: 'mark') are left out, as in CSV. A multiselect (array) value stays an array with text: 'value' and is the item labels joined by the separator with shown.

JSON ​

OptionValueDefaultEffect
prettybooleanfalseIndents the output
spaceinteger 1-82Indent width when pretty

A missing value is null. A date is the text stored in the column. Without rows the result is [].

XML ​

xml
<?xml version="1.0" encoding="UTF-8"?>
<rows>
  <row>
    <id>1</id>
    <name>Kim &amp; team</name>
    <tags>
      <item>a</item>
    </tags>
    <joined nil="true"/>
  </row>
</rows>
RuleContent
Declaration, rootUTF-8 declaration, root <rows> (root), one <row> per row (rowTag); an invalid name is an invalid-option
Column elementThe column id when it is a valid XML name, otherwise <cell id="…">
ValuesNumbers via String, dates as ISO, booleans as true/false, arrays as one <item> each, missing values as nil="true"
Escaping& < > " ' become entities; control characters XML cannot hold and lone surrogates are dropped
prettyDefault true; false gives one line

Text table ​

getTextTable({ header: true }) returns the displayed text as a 2-D array, handy for reports or other tools. A missing value is an empty string.

See also ​