Export Telerik RadGrid with EditMode lines - excel

I need to export a RadGrid table, and it contains several EditMode lines.
I would like to choose which content to export or ideally, if possible, change the lines to
EditMode = false
before exporting, so it looks how I need.
Code Details:
I have a few GridTemplateColumn, here is one of them:
<telerik:GridTemplateColumn
ItemStyle-Wrap="false" UniqueName="DataInicioAtividade"
DataField="DataInicioAtividade" HeaderText="*Data Inicio">
<ItemTemplate>
<telerik:RadDatePicker runat="server" ID="data_inicio" MinDate="1900/1/1">
<DateInput runat="server"
CssClass="date-picker" ID="rad_dateInput_data_inicio"
MaxLength="10" CausesValidation="true" />
</telerik:RadDatePicker>
</ItemTemplate>
</telerik:GridTemplateColumn>
And a button that simply executes the code:
rgd_grid_naoiniciada.ExportExcel();
The problem is, as it looks, telerik RadGrid exporting just dumps the HTML code of the resulting table to an Excel file.
The behaviour of the component is just like it should be, but the resulting file should have the field values, instead of HTML code containing input fields, links, images of RadCalendar etc...
Thanks in advance.

When you export Set the Templatecolumn values to the text property of Template column and then give ExportOnlyData="true";
This will work for Template columns also now.
In ItemBoundEvent, give the following code.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if ((isExport) && (e.Item is GridDataItem))
{
GridDataItem item = e.Item as GridDataItem;
item["DataInicioAtividade"].Text = ((RadDatePicker)item["DataInicioAtividade"].FindControl("data_inicio")).SelectedDate.ToString();
}
}

Related

dataExporter (Excel and CSV) not exporting the dataTableCommandLink values - PrimesFaces and JSF

I have few columns in the Data Table which displays the column name and row values dynamically.
But the first column in the data table have the values which has link. when we click that value it redirects to other screen.
Problem is when we export the csv/excel report. The first column which has this hyperlink not displaying the exact values. it shows as below in the excel
org.primefaces.component.column.Column#72d586ad - instead of exact value like "S123456789"
Please suggest how to display the exact value in the excel and csv.
<p:column headerText="#{msg['column.header']}" width="100" styleClass="columnLeft" filterBy="#{sampleDTO.linkNum}" sortBy="#{sampleDTO.linkNum}" id="linkNum">
<e:dataTableCommandLink id="viewTestLink" index="#{index}" value="#{sampleDTO.linkNum}" bean="#{sampleListBean}" action="viewLinkViewer"
ajax="false" currentDto="#{sampleDTO}"/>
</p:column>
Thanks in advance
Nithyn K
OK the reason its happening is because you are using a custom component <e:dataTableCommandLink which is why it can't figure out what text to display.
Here is what I would do use the ExportFunction...
Create a custom exporter my example uses CDI.
#Named
#ApplicationScoped
public class PassthroughColumnExporter {
public String export(final UIColumn column) {
String value = StringUtils.EMPTY;
for (final UIComponent child : column.getChildren()) {
final Object exportValue = child.getAttributes().get("data-export");
if (exportValue != null) {
value = String.valueOf(exportValue);
break;
}
}
return value;
}
}
In your XHTML use this custom exporter to export the value you want looking for the data-export attribute.
<p:column exportFunction="#{passthroughColumnExporter.export}">
<e:dataTableCommandLink value="#{row.displayValue}" data-export="#{row.exportValue}" />
</p:column>

How can I get a selector to do a partial lookup on any field in the list

I have a selector that is selecting cases among several other fields, as follows:
[PXSelector(typeof(Search2<CRCase.caseCD,
InnerJoin<PMProject,
On<CRCase.customerID, Equal<PMProject.customerID>>>,
Where<PMProject.contractID, Equal<Current<EPTimecardDetail.projectID>>>,
OrderBy<Desc<CRCase.caseCD>>>),
typeof(CRCase.caseCD),
typeof(CRCase.subject),
typeof(CRCase.createdDateTime),
typeof(CRCase.caseClassID),
typeof(CRCase.status),
typeof(CRCase.contactID),
typeof(CRCase.ownerID))]
When the selector is open, the search bar will only search on the first field - the CaseCD. If I type part of the Subject field text, I want it to show, as in other lookups, the entries that have that snippet of text in them. i.e., if I know part of the Subject field, I want it to filter or show entries filtered on that bit of text I enter.
Is there a setting in the PXSelector attribute that allows this, or would it be on the aspx page for the Selector?
In the past (unless there is something new) we set the FastFilterFields in the page.
Ex from project entry on contract cd (page PM301000):
<px:PXSegmentMask ID="edContractCD" runat="server" DataField="ContractCD" DataSourceID="ds" AutoRefresh="True">
<GridProperties FastFilterFields="Description, CustomerID, CustomerID_Customer_acctName" />
</px:PXSegmentMask>
Each field listed in FastFilterFields will be searchable in the selector.
Use of FastFilterFields will apply to PXSegmentMask or PXSelector.
Another example showing selector:
<px:PXSelector ID="edReceiptNbr" runat="server" DataField="ReceiptNbr" AutoRefresh="true">
<GridProperties FastFilterFields="InvoiceNbr, VendorID, VendorID_Vendor_acctName">
</GridProperties>
</px:PXSelector>

Xpages Extlib dataView control sets "display:none;" style when column has empty value

I have a xpage with Extension Library DataView control. I have defined several extra columns there.
<xe:dataView id="dataView1"
<xe:this.data>
<xp:dominoView var="vMyView" />
</xe:this.data>
<xe:this.summaryColumn>
<xe:viewSummaryColumn columnName="$DateFrom"
columnTitle="Date From">
</xe:viewSummaryColumn>
</xe:this.summaryColumn>
<xe:this.extraColumns>
<xe:viewExtraColumn columnName="$DateTo"
styleClass="hidden-xs" headerStyleClass="hidden-xs" columnTitle="Date To"
style="hidden-xs">
</xe:viewExtraColumn>
<xe:viewExtraColumn columnName="$Information"
columnTitle="Information">
</xe:viewExtraColumn>
</xe:this.extraColumns>
</xe:dataView>
My view data source contains same cells where information is empty. Those cells are rendered with style="display:none;".
How can I avoid this attribute and display those empty cells? I'd like not to change my view to fill empty cells with i.e. "-" char
An empty column value gets rendered with style="display:none;":
You can avoid this if you add a custom converter to your column definition and replace an empty value by a space:
<xe:viewExtraColumn columnName="$Information"
columnTitle="Information">
<xe:this.converter>
<xp:customConverter>
<xp:this.getAsString><![CDATA[#{javascript:value == "" ? " " : value}]]></xp:this.getAsString>
<xp:this.getAsObject><![CDATA[#{javascript:value}]]></xp:this.getAsObject>
</xp:customConverter>
</xe:this.converter>
</xe:viewExtraColumn>
It gets rendered to a "normal" grid cell without display:none then:
The code for getAsObject doesn't matter as long as the cell is not editable. So it's OK to just leave the value as it is.
Instead of using a converter to "fake" some content, you could also adjust the css. Just implement
.lotusTable TD {
display: inline !important;
}
in a style sheet resource used in your custom control(s).
So you also won't have to apply a converter to every potentially empty column.

How can I initially hide columns in a p:dataTable with p:columnToggler

I'm using PrimeFaces v.5 with this version a new component is released that ColumnToggler, when view is rendered, refreshed all checkbox are checked as a default operation.
What I need to do is;
to uncheck some columns when I initialize the view,
make p:columnToggler remember checked and unchecked options when a refresh operation occurs on p:dataTable
In Primefaces 5.2 you can set the p:column visible attribute to false
<p:column ... visible="false">
You can ofcourse use EL in the visible attribute by colum index (reordering becomes more difficult)
<p:column ... visible="#{visibilityModel.visibleList[1]}">
It hides the column at the beginning depending on the return value and you can show/hide the column through the columnToggler checkbox
By using the ajax toggle event
<p:ajax event="toggle" listener="#{viewBean.onToggle}" />
You can update the state of the visibilityModel server side
public void onToggle(ToggleEvent e) {
list.set((Integer) e.getData(), e.getVisibility() == Visibility.VISIBLE);
}
See this PrimeFaces blog entry for full example to actually keep/store the state of the visibility server side so it can be reused later
The best solution depends on the PrimeFaces version you are using.
PrimeFaces >= 5.2
See the other answer in this question.
workaround for < 5.2
You need to solve the first problem manually by overriding Primefaces' own ColumnToggler.prototype.render() function
first add styleClass="not-show-at-start" to your column that you want to insvisibe at start to access in javascript render() function;
<!--This column will not be shown at start-->
<p:column headerText="Cloumn to hide initially" width="70" styleClass="not-show-at-start">
<h:outputText value="#{entityVar.nmProcessOwner}" />
</p:column>
<!--This column will be shown at start-->
<p:column headerText="Column to show initially" width="70">
<h:outputText value="#{entityVar.nmProcessOwner}" />
</p:column>
secondy create a javascript file and paste code below in it, this function will re assign render function of ColumnToggler
PrimeFaces.widget.ColumnToggler.prototype.render = function() {
//variable for creating id referance for each checkbox in ColumnToggler
var id=0;
this.columns = this.thead.find("> tr > th:visible:not(.ui-static-column)");
this.panel = $("<div></div>").attr("id", this.cfg.id).addClass("ui-columntoggler ui-widget ui-widget-content ui-shadow ui-corner-all").append('<ul class="ui-columntoggler-items"></ul').appendTo(document.body);
this.itemContainer = this.panel.children("ul");
for (var a = 0; a < this.columns.length; a++) {
id++;
var b = this.columns.eq(a);
$('<li class="ui-columntoggler-item"><div class="ui-chkbox ui-widget"><div id="cb'+id /*creating id for each checkbox for accessing later*/+'" class="ui-chkbox-box ui-widget ui-corner-all ui-state-default ui-state-active"><span class="ui-chkbox-icon ui-icon ui-icon-check"></span></div></div><label>' + b.children(".ui-column-title").text() + "</label></li>").data("column", b.attr("id")).appendTo(this.itemContainer);
//access clumns using class reference(not-show-at-start) created in jsf page
if(b.hasClass( "not-show-at-start")){
//access checkbox using id attribute created above and uncheck it
//this will hide columns that have "not-show-at-start" class
this.uncheck($('#cb'+id));
}
}
this.hide();
}
An alternative solution could be to set directly the checkbox you want to uncheck after you load the page. It's a less elegant solution but it works. I did it this way:
<h:body onload="javascript:
$('.ui-chkbox-box')[18].click();">
By this way, after loading the page, javascript hide the column referenced by chechbox number 18 but the checkbox is still present on the columnToggler for the user to check it and show the column again if he wants to.
Greetings
Complementing Damián answer:
$(function() {
$('.ui-columntoggler-items .ui-chkbox .ui-chkbox-box').click();
});
This will do the job, clicking the columntoggler chkbox after page load..
#Edit
You should set as toggleable="false" the columns you don't want to hide (always displayed)
Reason: if you use the javascript method to "override" primefaces toggler, sometimes the datatable column shown can be displayed wrong in the layout (out of the table size, for an example, like happened with me), that's why i decided to use the method described above..

How to Disable ToolTip without Removing the "title" attribute [ASP.NET]

I have 3 TextBoxes
<asp:TextBox ID="txtTitle" runat="server" class="txtFields" title="Title" />
<asp:TextBox ID="txtName" runat="server" class="txtFields" title="Name" />
<asp:TextBox ID="txtDescription" runat="server" class="txtFields" title="Description" />
I'm using the watermark plugin on these 3 TextBoxes:
jQuery('.txtFields').watermark();
This is the plugin:
http://code.google.com/p/jquery-watermark/
jQuery('.txtFields').watermark();
Uses the Title Attribute of the TextBox to Show the Watermark but the problem is that this also Generates ToolTips which is something I do Not want, is there anyway to disable the tooltips without removing the title attribute?
Or is there anyway to use custom attributes with this plugin? By that I mean making the plugin use another attribute instead of the title attribute.
Thank you.
Looks like watermark will allow you to specify any text to display in there, so you're not stuck with the title. Any attribute that you could select with jQuery you could use as the watermark value. The problem with that is there are no other attributes you could add in there and still have nice compliant code. Best bet is to give them a value, assign a variable that value, unset it and add watermark. Something like:
$('input').each(function() {
var wmark = $(this).val();
$(this).val('');
$(this).watermark(wmark);
});
Try adding UseAccessibleHeader = false
like this:
<asp:TextBox ID="txtTitle" runat="server" class="txtFields" title="Title" UseAccessibleHeader = false />

Resources