Author Topic: export to excel for data with checkboxes and hyperlinks  (Read 1984 times)

kshipra

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 94
    • View Profile
export to excel for data with checkboxes and hyperlinks
« on: November 16, 2017, 04:07:07 am »
On render for name column there is hyperlink and for boolean column there is check box.

hyperlink code for column render

 
Code: [Select]
if (ui.column.dataIndx === "Name") {
                        var encodeUriComponent = encodeURIComponent(result);
                        return "<a style='text-decoration:underline;' href=/abc/xyz?Id=" + $('#ddlFoo').val() + "&Name=" + encodeUriComponent + " target='_blank'>" +
                            result +
                            "</a>";
                     
                    } else {
                        return result;
                    }

checkbox render:
-------------------------------------------

 var cb = ui.column.cb,
                        cellData = ui.cellData,
                        checked = cb.check === cellData ? 'checked' : '',
                        disabled = this.isEditableCell(ui) ? "" : "disabled",
                        text = cb.check === cellData ? 'TRUE' : (cb.uncheck === cellData ? 'FALSE' : '<i>unknown</i>');
                    return {
                        text: "<label><input type='checkbox' " + checked + " />" + text + "</label>",
                        style: (disabled ? "background:lightgray" : "")
                    };

On export to excel, the boolean columns has this, same is case for hyperlink column, it shows html.
IsDeleted
<label><input type='checkbox'  />FALSE</label>
<label><input type='checkbox'  />FALSE</label>
<label><input type='checkbox'  />FALSE</label>
<label><input type='checkbox'  />FALSE</label>
<label><input type='checkbox'  />FALSE</label>


Ideally I don't want to remove all this formatting in beforeExport event for multiple columns. I am not sure how I do that also. Code is going to be messy.
 Any suggestions ?

if column is of type checkbox, why does not it get rendered as checkbox, why in render do I need to create checkbox input ?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: export to excel for data with checkboxes and hyperlinks
« Reply #1 on: November 16, 2017, 05:53:09 pm »
1. use exportRender: false to prevent export of rendered value of cells.

https://paramquery.com/pro/api#option-column-exportRender

2. When column.type = 'checkbox', there is no need to use render to create checkboxes unless there is a need for custom rendering of the cells.