Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
190
igGrid 16.1 - Complex Objects & Exporting
posted

I have the following grid below, for this purpose assume both the state / user api will return an id & name.   I am unable to export this grid however, as I get the following error when attempting it.   Are we able to export grids with complex objects?  If so, could you provide an example?

infragistics.excel.js:79 Uncaught TypeError: a.getType is not a function$c.a0 @ infragistics.excel.js:79$c.ay @ infragistics.excel.js:79$c.ao @ infragistics.excel.js:79$c._d1 @ infragistics.excel.js:49$c.setCellValue @ infragistics.excel.js:48$.ig.GridExcelExporter.$.ig.GridExcelExporter.Class.extend._exportCell @ infragistics.gridexcelexporter.js:23$.ig.GridExcelExporter.$.ig.GridExcelExporter.Class.extend._exportDataSegmentRow @ infragistics.gridexcelexporter.js:23$.ig.GridExcelExporter.$.ig.GridExcelExporter.Class.extend._exportDataSegment @ infragistics.gridexcelexporter.js:23(anonymous function) @ infragistics.gridexcelexporter.js:23

    $("#grid").igGrid({
        virtualization: false,
        primaryKey: "id",
        responseDataKey: "value",
        autoGenerateColumns: false,
        autoGenerateLayouts: false,
        localSchemaTransform: true,
        renderCheckboxes: true,
        columns: [{
            // note: if primaryKey is set and data in primary column contains numbers,
            // then the dataType: "number" is required, otherwise, dataSource may misbehave
            headerText: "Id", key: "id", dataType: "number"
        },
		{
		    headerText: "Year", key: "year", dataType: "string"
		},
		{
		    headerText: "State", key: "state", dataType: "object", width:250, mapper: function (record) { return record.state.name; }
		},
		{
		    headerText: "User", key: "user", dataType: "object", width:250, mapper: function (record) {
		        if (record.user != null)
		        { return record.user.name; }
		        else
		        { return null; }
		    }
		}
        ],
        width: "500",
        features: [
	    {
	        name: "Updating",
	        enableAddRow: false,
	        enableDeleteRow: false,
	        editMode: "cell",
	        columnSettings: [
	            {
	                columnKey: "user",
	                editorType: "combo",
	                editorOptions: {
	                    dataSource: "/api/usersapi/",
	                    textKey: "name",
	                    valueKey: "id",
                        mode: "editable"
	                }
	            },
                {
                	columnKey: "state",
                	editorType: "combo",
                    disabled: true,
                	editorOptions: {
                	    dataSource: "/api/statesapi/",
                	    textKey: "name",
                	    valueKey: "id",
                	    mode: "dropdown"
                	}
                },
                { columnKey: "id", editorOptions: { disabled: true } },
                { columnKey: "year", editorOptions: { disabled: true } }
                
	        ]
	    },
            {
                name: "Hiding",
                columnSettings: [
                    { columnKey: "id", allowHiding: false, hidden: true },
                    { columnKey: "year", allowHiding: false, hidden: true }
 
                ]
            },
 
        ]
 
 
    });
Parents
  • 16310
    Offline posted

    Hello Brian,

    Currently the igGridExcelExporter looks for a formatter function to export complex objects. However in 16,1 the mapper function was introduced in igGrid to deal with complex objects and the igGridExcelExporter does not yet handle that update. I have logged this development issue in our internal system so that it gets attention. The fix should be available in next service release of Ignite UI.

    Meanwhile I suggest that you define a formatter function, which will enable you to export complex object in the given scenario:

    { key: "User", headerText: "User", dataType: "object", width: "150px", 
     mapper: function (record) {
      if (record.User != null) {
       return record.User.Name;
      } else
      {
       return null;
      }
     }, formatter: formatFunc
    },

    // when the igGrid calls formatFunc, val will be the value extracted by the mapper, i.e record.User.Name, which would be "John"
    // when the igGridExcelExporter calls formatFunc, val will be the complex object, i.e record.User, which would be "User": { "id": 9, "Name": "John" }

    function formatFunc(val) {
     if (typeof(val) === "object") {
      return val.Name;
     } else {
      return val;
     } 
    }

    Please let me know if you have further questions on the matter, I will be glad to help.

Reply Children