Hi Isomorphic,
reading these docs it should be possible to export displayField with ListGrid.exportData() somehow:
These docs also say "note, exportValueFields has no effect for server-driven exports" which contradicts it's own docs which say:
So to me it seems that the 1st docs have an error in that sentence as well as in missing a checkBox for "exportData(), valueMap declared in DataSource".
Regardless of these issues, the feature itself is not working for me at all (v12.0p_2020-03-11):
The exported XLS in the attached BuiltInDS sample always results in an "Owner" column filled with IDs, where I'd expect employee-Names and empty fields, like in the GUI. This is for either settings of exportValueFields (see testcase).
Additionally, the sort for the export SQL, is wrong:
BuiltInDS.java:
animals.ds.xml:
Best regards
Blama
reading these docs it should be possible to export displayField with ListGrid.exportData() somehow:
| exportData(), in-record displayField (must be declared in DataSource) | ✓ | ✓ |
| exportData(), valueMap declared in DataSource | ✓ | |
| exportData(), valueMap defined in code | ✓ | |
| exportData(), optionDataSource | ✓ |
For exportData() calls (server-driven), we ordinarily export the underlying data value of all fields. However, if you set the exportValueFields property explicitly to false, any fields that have a DataSource-defined valueMap will have the mapped value exported instead. This is similar to the client-side treatment of valueMaps, except that the defaults are reversed.
Regardless of these issues, the feature itself is not working for me at all (v12.0p_2020-03-11):
The exported XLS in the attached BuiltInDS sample always results in an "Owner" column filled with IDs, where I'd expect employee-Names and empty fields, like in the GUI. This is for either settings of exportValueFields (see testcase).
Additionally, the sort for the export SQL, is wrong:
Code:
GUI, correct: ...FROM animals LEFT OUTER JOIN employeeTable ON animals.lifeSpan = employeeTable.EmployeeId WHERE ('1'='1') [B]ORDER BY employeeName[/B]
Export, incorrect: ...FROM animals LEFT OUTER JOIN employeeTable ON animals.lifeSpan = employeeTable.EmployeeId WHERE ('1'='1') [B]ORDER BY animals.lifeSpan[/B]
Code:
package com.smartgwt.sample.client;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.Version;
import com.smartgwt.client.core.KeyIdentifier;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.SortSpecifier;
import com.smartgwt.client.types.ExportFormat;
import com.smartgwt.client.types.SortDirection;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.util.Page;
import com.smartgwt.client.util.PageKeyHandler;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.IButton;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.grid.HeaderSpan;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;
public class BuiltInDS implements EntryPoint {
private VLayout mainLayout;
private IButton recreateBtn;
private Boolean exportValueFields;
public void onModuleLoad() {
KeyIdentifier debugKey = new KeyIdentifier();
debugKey.setCtrlKey(true);
debugKey.setKeyName("D");
Page.registerKey(debugKey, new PageKeyHandler() {
public void execute(String keyName) {
SC.showConsole();
}
});
mainLayout = new VLayout(20);
mainLayout.setWidth100();
mainLayout.setHeight100();
recreateBtn = new IButton("Recreate");
recreateBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
recreate();
}
});
mainLayout.addMember(recreateBtn);
recreate();
mainLayout.draw();
}
private void recreate() {
Window w = new Window();
w.setWidth("95%");
w.setHeight("95%");
w.setMembersMargin(0);
w.setModalMaskOpacity(70);
w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
w.setTitle("Problem with export of displayFields and sorting" + w.getTitle());
w.setShowMinimizeButton(false);
w.setIsModal(true);
w.setShowModalMask(true);
w.centerInPage();
final ListGrid animalsGrid = new ListGrid(DataSource.get("animals"));
animalsGrid.setHeight100();
animalsGrid.setAutoFetchData(true);
animalsGrid.setCanEdit(true);
animalsGrid.setCanRemoveRecords(true);
animalsGrid.setHeaderHeight(40);
animalsGrid.setExportFieldWidths(true);
ListGridField scientificName = new ListGridField("scientificName");
scientificName.setCanEdit(false);
ListGridField commonName = new ListGridField("commonName");
ListGridField diet = new ListGridField("diet");
ListGridField information = new ListGridField("information");
information.setHidden(true);
ListGridField status = new ListGridField("status");
ListGridField lifeSpan = new ListGridField("lifeSpan");
lifeSpan.setEditorProperties(new SelectItem() {
{
ListGridField employeeID = new ListGridField("EmployeeId");
ListGridField employeeName = new ListGridField("Name");
setAllowEmptyValue(true);
setPickListFields(employeeID, employeeName);
setSortField("Name");
}
});
ListGridField employeeEmployeeId = new ListGridField("employeeEmployeeId");
ListGridField employeeName = new ListGridField("employeeName");
animalsGrid
.setHeaderSpans(new HeaderSpan("includeFrom fields", new String[] { employeeEmployeeId.getName(), employeeName.getName(), }));
animalsGrid.setFields(scientificName, commonName, diet, information, status, lifeSpan, employeeEmployeeId, employeeName);
animalsGrid.setSort(new SortSpecifier[] { new SortSpecifier(scientificName.getName(), SortDirection.ASCENDING) });
HLayout buttonsLayout = new HLayout(10) {
{
setHeight(30);
setWidth100();
setDefaultLayoutAlign(VerticalAlignment.CENTER);
IButton exportDataBtn = new IButton("exportData()", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
doExport(animalsGrid);
}
});
IButton exportClientDataBtn = new IButton("exportClientData()", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
doClientExport(animalsGrid);
}
});
IButton invalidateCacheBtn = new IButton("invalidateCache()", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
animalsGrid.invalidateCache();
}
});
IButton filterRowBtn = new IButton("Toggle filterRow", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
animalsGrid.setShowFilterEditor(!animalsGrid.getShowFilterEditor());
}
});
IButton exportValueFieldsTrueBtn = new IButton("exportValueFields: true", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
exportValueFields = true;
}
});
IButton exportValueFieldsFalseBtn = new IButton("exportValueFields: false", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
exportValueFields = false;
}
});
addMembers(exportDataBtn, exportClientDataBtn, invalidateCacheBtn, filterRowBtn, exportValueFieldsTrueBtn,
exportValueFieldsFalseBtn);
}
};
VLayout vLayout = new VLayout() {
{
addMembers(animalsGrid, buttonsLayout);
}
};
w.addItem(vLayout);
w.show();
}
private void doExport(ListGrid workLG) {
// The field list to use for the export
final List<String> exportFieldList = getVisibleFieldList(workLG);
// The export request to use (direct, no-load-all, load-all)
final DSRequest exportRequest = new DSRequest() {
{
setExportAs(ExportFormat.OOXML);
setExportFilename("myExport");
setExportFields(exportFieldList.toArray(new String[exportFieldList.size()]));
setExportValueFields(exportValueFields);
}
};
workLG.exportData(exportRequest);
}
private void doClientExport(ListGrid workLG) {
// The field list to use for the export
final List<String> exportFieldList = getVisibleFieldList(workLG);
// The export request to use (direct, no-load-all, load-all)
final DSRequest exportRequest = new DSRequest() {
{
setExportAs(ExportFormat.OOXML);
setExportFilename("myExport");
setExportFields(exportFieldList.toArray(new String[exportFieldList.size()]));
}
};
workLG.exportClientData(exportRequest);
}
private List<String> getVisibleFieldList(ListGrid lg) {
List<String> visibleFieldList = new ArrayList<String>();
for (ListGridField lgf : lg.getFields())
if (lg.fieldIsVisible(lgf.getName()) && (lgf.getCanExport() == null || lgf.getCanExport()))
visibleFieldList.add(lgf.getName());
return visibleFieldList;
}
}
Code:
<DataSource
ID="animals"
serverType="sql"
tableName="animals"
testFileName="animals.data.xml" useAnsiJoins="true"
>
<fields>
<field name="commonName" title="Animal" type="text" sortByField="diet" />
<field name="scientificName" title="Scientific Name" type="text" primaryKey="true" required="true" />
<field name="lifeSpan" title="Life Span" type="integer"/>
<field name="status" title="Endangered Status" type="text">
<valueMap>
<value>Threatened</value>
<value>Endangered</value>
<value>Not Endangered</value>
<value>Not currently listed</value>
<value>May become threatened</value>
<value>Protected</value>
</valueMap>
</field>
<field name="diet" title="Diet" type="text"/>
<field name="information" title="Interesting Facts" type="text" length="1000"/>
<field name="picture" title="Picture" type="image" detail="true"
imageURLPrefix="/isomorphic/system/reference/inlineExamples/tiles/images/"/>
<field foreignKey="employees.EmployeeId" name="lifeSpan" title="Owner" type="integer" joinType="outer" displayField="employeeName" />
<field name="employeeEmployeeId" includeFrom="employees.EmployeeId" title="employeeEmployeeId-iF" />
<field name="employeeName" includeFrom="employees.Name" title="employeeName-iF" />
</fields>
</DataSource>
Best regards
Blama
Comment