Scroll

Server Event: Remove invalid sort fields

Use this server event to eliminate unsortable fields, such as images, from the Sorts dialog in the report wizard and report designer.

Global Event: OnDataFieldsRetrieved

References:

  • System.data.dll,
  • System.xml.dll

Namespaces:

  • WebReports.Api.Reports,
  • System.Diagnostics,
  • System.Data

Code

DataTable dt = args[0] as DataTable;
Entity entity = args[1] as Entity;

// determine if schema is being requested by the sorts control
StackTrace st = new StackTrace();
foreach (StackFrame sf in st.GetFrames())
{
  string ctrlName = sf.GetMethod().DeclaringType.Name;
  if (ctrlName == "SimpleSortsCtrl" || ctrlName == "ReportSortsDialog")
  {
    // request from the sorts window; check for invalid sort fields
    for (int i = 0; i < dt.Rows.Count; i++)
    {
      string columnName = dt.Rows[i]["column_name"].ToString();
      string dataType = dt.Rows[i]["data_type"].ToString();

      // look for metadata
      if (entity.ColumnMetadatas.Count > 0)
      {
        dataType = entity.ColumnMetadatas.GetDataType(columnName, dataType);
      }

      // remove image data types
      if (String.Compare(dataType, "image", true) == 0)
      {
        dt.Rows.RemoveAt(i);
        i--;
      }
    }
    break;
  }
}

// sort list and return
DataView dv = dt.DefaultView;
dv.Sort = "column_name desc";
return dv.ToTable();

Hidden Article Information

Article Author
Exago Development
created 2016-02-29 20:52:37 UTC
updated 2017-06-19 17:36:03 UTC

Labels
sort, SAE, server event, events, example, unsortable, nonsortable, invalid,
Have more questions? Submit a request