Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Hidden ListGridField used for grouping is not exported

    Hi Isomorphic,

    I have a dense ListGrid showing all needed columns without scrolling.

    The ListGrid and the relevant ListGridField are configured as follows:

    Code:
    lg.setGroupByMaxRecords(200);
    lg.setGroupStartOpen(GroupStartOpen.ALL);
    lg.setCanGroupBy(false);
    
    ListGridFieldLeadstatus statusNameLGFHidden = new ListGridFieldLeadstatus("STATUS_SHORTNAME");
    statusNameLGFHidden.setHidden(true);
    statusNameLGFHidden.setCanHide(false);
    statusNameLGFHidden.setCanExport(true);
    
    lg.setGroupByField("STATUS_SHORTNAME");
    lg.setFields(statusNameLGFHidden, ...);
    lg.setSort(new SortSpecifier[] { new SortSpecifier("STATUS_SHORTNAME", SortDirection.ASCENDING), ...});
    lg.fetchData();
    ListGridFieldLeadstatus subclasses ListGridField and uses setGroupTitleRenderer(). That way I group my entries and have the relevant information in the grouping-row, not squandering valuable horizontal space.
    When I try to export the ListGrid using
    Code:
    DSRequest requestProperties = new DSRequest() {
    	{
    		setExportAs(ExportFormat.OOXML);
    		setExportFilename(exportFileName);
    	}
    };
    lg.exportClientData(requestProperties);
    all displayed columns are exported, but not the hidden grouping column.
    I don't know if this is a bug. I'd say so, because the column information is displayed, but not as column. If one does not want the data exported, he could still set setCanExport(false).

    If it is a bug, it would be great if you could fix it in 4.1p (I'm using v9.1p_2014-11-05).

    Best regards,
    Blama

    #2
    We would not regard this as a bug, since you get a "what you see if what you get" export as expected.

    If you want to include the grouped column, you can use dsRequest.exportFields.

    Comment


      #3
      Hi Isomorphic,

      I'm afraid that does not work. Please see this testcase based on BuiltInDS:
      Code:
      package com.smartgwt.sample.client;
      
      import com.google.gwt.core.client.EntryPoint;
      import com.smartgwt.client.core.KeyIdentifier;
      import com.smartgwt.client.data.DSRequest;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.data.Record;
      import com.smartgwt.client.types.ExportFormat;
      import com.smartgwt.client.types.SelectionStyle;
      import com.smartgwt.client.types.SortArrow;
      import com.smartgwt.client.util.PageKeyHandler;
      import com.smartgwt.client.util.Page;
      import com.smartgwt.client.util.SC;
      import com.smartgwt.client.widgets.IButton;
      import com.smartgwt.client.widgets.Label;
      import com.smartgwt.client.widgets.events.ClickEvent;
      import com.smartgwt.client.widgets.events.ClickHandler;
      import com.smartgwt.client.widgets.form.DynamicForm;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.grid.ListGridField;
      import com.smartgwt.client.widgets.grid.ListGridRecord;
      import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
      import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
      import com.smartgwt.client.widgets.layout.HLayout;
      import com.smartgwt.client.widgets.layout.VStack;
      import com.smartgwt.client.widgets.viewer.DetailViewer;
      
      /**
       * Entry point classes define <code>onModuleLoad()</code>.
       */
      public class BuiltInDS implements EntryPoint {
      	private ListGrid boundList;
      	private DynamicForm boundForm;
      	private IButton exportBtn;
      	private IButton saveBtn;
      	private DetailViewer boundViewer;
      	private IButton newBtn;
      
      	/**
      	 * This is the entry point method.
      	 */
      	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();
      			}
      		});
      
      		ListGrid grid = new ListGrid();
      		grid.setLeft(20);
      		grid.setTop(75);
      		grid.setWidth(130);
      		grid.setLeaveScrollbarGap(false);
      		grid.setShowSortArrow(SortArrow.NONE);
      		grid.setCanSort(false);
      		grid.setFields(new ListGridField("dsTitle", "Select a DataSource"));
      		grid.setData(new ListGridRecord[] { new DSRecord("Animals", "animals"), new DSRecord("Office Supplies", "supplyItem"),
      				new DSRecord("Employees", "employees") });
      		grid.setSelectionType(SelectionStyle.SINGLE);
      		grid.addRecordClickHandler(new RecordClickHandler() {
      			public void onRecordClick(RecordClickEvent event) {
      				DSRecord record = (DSRecord) event.getRecord();
      				bindComponents(record.getDsName());
      			}
      		});
      
      		grid.draw();
      
      		VStack vStack = new VStack();
      		vStack.setLeft(175);
      		vStack.setTop(75);
      		vStack.setWidth("70%");
      		vStack.setMembersMargin(20);
      
      		Label label = new Label();
      		label.setContents("<ul>" + "<li>select a datasource from the list at left to bind to these components</li>"
      				+ "<li>click a record in the grid to view and edit that record in the form</li>"
      				+ "<li>click <b>New</b> to start editing a new record in the form</li>"
      				+ "<li>click <b>Save</b> to save changes to a new or edited record in the form</li>"
      				+ "<li>click <b>Clear</b> to clear all fields in the form</li>"
      				+ "<li>click <b>Filter</b> to filter (substring match) the grid based on form values</li>"
      				+ "<li>click <b>Fetch</b> to fetch records (exact match) for the grid based on form values</li>"
      				+ "<li>double-click a record in the grid to edit inline (press Return, or arrow/tab to another record, to save)</li>" + "</ul>");
      		vStack.addMember(label);
      
      		boundList = new ListGrid();
      		boundList.setHeight(200);
      		boundList.setCanEdit(true);
      		boundList.setCanPickFields(true);
      
      		boundList.addRecordClickHandler(new RecordClickHandler() {
      			public void onRecordClick(RecordClickEvent event) {
      				Record record = event.getRecord();
      				boundForm.editRecord(record);
      				saveBtn.enable();
      				boundViewer.viewSelectedData(boundList);
      			}
      		});
      		vStack.addMember(boundList);
      
      		boundForm = new DynamicForm();
      		boundForm.setNumCols(6);
      		boundForm.setAutoFocus(false);
      		vStack.addMember(boundForm);
      
      		HLayout hLayout = new HLayout(10);
      		hLayout.setMembersMargin(10);
      		hLayout.setHeight(22);
      
      		exportBtn = new IButton("Export");
      		exportBtn.addClickHandler(new ClickHandler() {
      			public void onClick(ClickEvent event) {
      				DSRequest exportReq = new DSRequest() {
      					{
      						setExportAs(ExportFormat.OOXML);
      						setExportFilename("exportTest");
      						setExportFields(new String[] { "commonName", "scientificName", "lifeSpan", "status", "diet", "information" });
      					}
      				};
      				boundList.exportClientData(exportReq);
      			}
      		});
      
      		saveBtn = new IButton("Save");
      		saveBtn.addClickHandler(new ClickHandler() {
      			public void onClick(ClickEvent event) {
      				boundForm.saveData();
      				if (!boundForm.hasErrors()) {
      					boundForm.clearValues();
      					saveBtn.disable();
      				}
      			}
      		});
      		hLayout.addMembers(exportBtn, saveBtn);
      
      		newBtn = new IButton("New");
      		newBtn.addClickHandler(new ClickHandler() {
      			public void onClick(ClickEvent event) {
      				boundForm.editNewRecord();
      				saveBtn.enable();
      			}
      		});
      		hLayout.addMember(newBtn);
      
      		IButton clearBtn = new IButton("Clear");
      		clearBtn.addClickHandler(new ClickHandler() {
      			public void onClick(ClickEvent event) {
      				boundForm.clearValues();
      				saveBtn.disable();
      			}
      		});
      		hLayout.addMember(clearBtn);
      
      		IButton filterBtn = new IButton("Filter");
      		filterBtn.addClickHandler(new ClickHandler() {
      			public void onClick(ClickEvent event) {
      				boundList.filterData(boundForm.getValuesAsCriteria());
      				saveBtn.disable();
      			}
      		});
      		hLayout.addMember(filterBtn);
      
      		IButton fetchBtn = new IButton("Fetch");
      		fetchBtn.addClickHandler(new ClickHandler() {
      			public void onClick(ClickEvent event) {
      				boundList.fetchData(boundForm.getValuesAsCriteria());
      				saveBtn.disable();
      			}
      		});
      		hLayout.addMember(fetchBtn);
      
      		vStack.addMember(hLayout);
      
      		boundViewer = new DetailViewer();
      		vStack.addMember(boundViewer);
      
      		vStack.draw();
      	}
      
      	private void bindComponents(String dsName) {
      		DataSource ds = DataSource.get(dsName);
      		boundList.setDataSource(ds);
      		boundViewer.setDataSource(ds);
      		boundForm.setDataSource(ds);
      		boundList.fetchData();
      		newBtn.enable();
      		saveBtn.disable();
      	}
      }
      Select "Animals", hide some columns and export. The Export should always have six columns (see exportReq), but for me (v9.1p_2014-11-05) it only includes the columns the ListGrid shows.

      As addition, could you add this method (or it's JS equivalent) to ListGrid? I did not find it anywhere and think it is useful for anyone:
      Code:
      private String[] getVisibleFieldList(ListGrid lg) {
      	List<String> l = new ArrayList<String>();
      	for (ListGridField lgf : lg.getFields())
      		if (!lgf.getHidden())
      			l.add(lgf.getName());
      	return l.toArray(new String[l.size()]);
      }
      It could also return a ListGridField[], but I needed String[] now to amend and feed to DSRequest.setExportFields().

      Best regards,
      Blama

      Comment


        #4
        exportFields applies to exportData(), but not to exportClientData(), which is intended to be a "what you see is what you get" export of the data as currently displayed on the client.

        If you insist on exporting the grouped field, one way to do it is to show that field immediately before asking for the export.

        listGrid.getFields() already returns you the list of currently visible fields, so there's no need for a helper method like you describe.

        Comment

        Working...
        X