How to sort on grid? How to sort columns in devexpress dynamically grid?
AutoGenerateColumns="true", runat="server"
dx:LinqServerModeDataSource
I am creating the columns dynamically but sorting on my grid is not working.
I tried many ways, my grids are working but I can't sort on any of the columns.
I am pulling data from database through another project and making databind for ID="ASPxGridViewData". grid and structure are working but sorting is not working, what is the missing way?
aspx code;
<div id="divDisplayFeatures" class="row" style="margin-top: 15px;display:none">
<div class="col-md-12">
<dx:ASPxWebDocumentViewer ID="ASPxWebDocumentViewerForReport" runat="server" ClientIDMode="Static" Visible="false"
ClientSideEvents-DocumentReady="function(s,e){ $('.dxrd-image-parameters').hide(); if($('#HiddenFieldPrintStatus').val() == 1) { s.Print(); }}">
</dx:ASPxWebDocumentViewer>
<dx:ASPxGridView ID="ASPxGridViewData" runat="server"
ClientIDMode="Static"
AutoGenerateColumns="true"
Styles-Header-BackColor="#ff7f00"
Styles-Header-Font-Bold="true"
Styles-Header-Font-Size="Small"
Styles-PagerBottomPanel-BackColor="#ff7f00"
Width="100%"
Visible="false"
AllowSorting="true"
Settings-AutoFilterCondition="Contains"
Settings-HorizontalScrollBarMode="Visible"
Settings-ShowFilterRow="true"
DataSourceID="LinqServerModeDataSourceForGrid"
OnDataBound="ASPxGridViewData_DataBound"
Styles-Header-Wrap="True">
<Columns ></Columns>
<SettingsPager PageSizeItemSettings-Items="5,10,25,50,100,200,500" PageSizeItemSettings-Visible="true"></SettingsPager>
</dx:ASPxGridView>
<dx:LinqServerModeDataSource ID="LinqServerModeDataSourceForGrid" runat="server" DefaultSorting="Id desc"
OnSelecting="LinqServerModeDataSourceForGrid_Selecting"></dx:LinqServerModeDataSource>
c# code;
protected string GetGridFilterString(DevExpress.Web.ASPxGridView grid)
{
var parse = DevExpress.Data.Filtering.CriteriaOperator.Parse(
grid.FilterExpression, 0);
var gridFilter =
DevExpress.Data.Filtering.CriteriaToWhereClauseHelper.GetDataSetWhere(
parse);
return gridFilter;
}
protected void DisplayReportView(object sender, EventArgs e)
{
try
{
panelButtons.Visible = true;
GenerateReportView(ReportGenerateType.Gridview);
}
catch (Exception ex)
{
ActivityLogManager.WriteLog(SmartFrame.Products.Enum.ProcessType.GenerateWebReport, ex.Message, SmartFrame.Products.Enum.ProcessStatus.FAILED);
throw ex;
}
}
protected void GenerateReportView(object sender, EventArgs e)
{
try
{
GenerateReportView(ReportGenerateType.Report);
}
catch (Exception ex)
{
ActivityLogManager.WriteLog(SmartFrame.Products.Enum.ProcessType.GenerateWebReport, ex.Message, SmartFrame.Products.Enum.ProcessStatus.FAILED);
throw ex;
}
}
private void GenerateReportView(ReportGenerateType ReportGenerateType)
{
try
{
if (!string.IsNullOrEmpty(PageData.ReportCode))
{
#region Set Report Parameters
var currentSystemUser = HttpContext.Current.Session["currentSystemUser"] as SmartFrame.SmartBase.NoSQL.Collections.SystemUser;
var selectedFacility = HttpContext.Current.Session["selectedFacility"] as SmartFrame.SmartBase.NoSQL.Collections.Facility;
var reportParameters = new SmartFrame.Report.Client.ReportContainer();
var myStations = new List<Station>();
if (SmartFrame.SmartBase.NoSQL.DataProvider.allStations.Where(x => x.FacilityID == selectedFacility.Id && currentSystemUser.Stations.Contains(x.Id)).ToList() != null)
myStations = SmartFrame.SmartBase.NoSQL.DataProvider.allStations.Where(x => x.FacilityID == selectedFacility.Id && currentSystemUser.Stations.Contains(x.Id)).ToList();
reportParameters.ReportSource = SmartFrame.Products.Enum.RequestSource.Web;
reportParameters.ReportCreatorUser = currentSystemUser.UserName;
reportParameters.ReportType = PageData.ReportCode;
reportParameters.ReportHeaderLogoPath = AppDomain.CurrentDomain.BaseDirectory + @"Resources\StockArtLogo_Black.png";
reportParameters.ReportHeaderTitle = LanguageProvider.GetLanguageText(HttpContext.Current.Session["currentLanguage"] as String, "ReportType" + PageData.ReportCode);
if (!string.IsNullOrEmpty(DatetimeStartDateTime.Text) && !string.IsNullOrEmpty(DatetimeEndDateTime.Text))
{
DateTime enteredDateStartDate = DateTime.Parse(DatetimeStartDateTime.Text);
DateTime enteredDateEndDate = DateTime.Parse(DatetimeEndDateTime.Text);
reportParameters.StartTime = enteredDateStartDate;
reportParameters.EndTime = enteredDateEndDate;
}
HiddenFieldPrintStatus.Value = "0";
var selectedTemplate = new SmartFrame.SmartBase.NoSQL.Collections.UserReportTemplateSetting();
PageData.ReportFieldSettings = new List<SmartFrame.SmartBase.NoSQL.RelatedClasses.ReportFieldSettings>();
var reportFilterSettings = new List<SmartFrame.SmartBase.NoSQL.RelatedClasses.ReportFilterSetting>();
var selectedTemplateId = Request["ctl00$MainContent$SelectForReportTemplates"];
if (string.IsNullOrEmpty(selectedTemplateId))
{
selectedTemplateId = Request["ctl00$MainContent$HiddenFieldSelectedTemplateId"];
}
if (!string.IsNullOrEmpty(selectedTemplateId))
{
selectedTemplate = genericController.GetOne<UserReportTemplateSetting>(x => x.Id == selectedTemplateId);
PageData.ReportFieldSettings = selectedTemplate.FieldSettingsList;
}
else
{
selectedTemplate = null;
PageData.ReportFieldSettings = null;
}
#endregion
switch (PageData.ReportCode)
{
case "A01":
if (ReportGenerateType == ReportGenerateType.Gridview)
{
var reportInstance = new SmartFrame.Report.Client.TwentyLeastUsedItemsReport(reportParameters);
if (PageData.ReportFieldSettings == null)
PageData.ReportFieldSettings = reportInstance.GenerateDefaultFieldSettings(new List<SmartFrame.SmartBase.NoSQL.RelatedClasses.ReportFieldSettings>());
reportInstance.InitializeReportData(reportInstance.FilterParameterDataList);
genericController.InitializeQueryableSession<SmartFrame.Report.DataSource.TwentyLeastUsedItemsData>("ExternalDataSource" + PageData.DynamicPageId);
Session["ExternalDataSource" + PageData.DynamicPageId] = reportInstance.GetReportDataQueryable().OrderBy(x => x.ItemName).OrderBy(x => x.Station);
ASPxGridViewData.DataBind();
}.............................
..................................................... ............................................ ........................................................... ............................................................ ...............................................
protected void LinqServerModeDataSourceForGrid_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
{
ASPxGridViewData.Columns.Clear();
ASPxGridViewData.AutoGenerateColumns = true;
e.KeyExpression = "Id";
e.QueryableSource = (IsCallback || IsPostBack) ?
Session["ExternalDataSource" + PageData.DynamicPageId] as IQueryable<object> :
new List<object>().AsQueryable();
}
how to sort on grid?