Databand sort numerics Nulls last

Is there a way to sort in Databand integer values that can contain NULL-Values as I do in MySQL --> ORDER BY IfNull(res.Heben_Platz, 1000) ASC?
If I pass the ordered datatable to FR using no sort expression it still sorts NULL,1,2... Even the integer values will be sorted like strings 1,10,11,2.
An sort expression like "IIf(not IsNull("protokoll.Heben_Platz"),[protokoll.Heben_Platz],1000)" does not help either.

Thanks for any help.

Comments

  • edited 6:40PM
    there are 2 methods:
    a. easy way : custom function
    b. hard way : linq
  • edited July 2018
    ipong wrote: »
    there are 2 methods:
    a. easy way : custom function
    b. hard way : linq

    First of all I do not understand how do you create the datasource "nullable".
    Then my datasource is a datatable derived from MySQL database with many Columns. I could build a sorted list from it (if sorted list is supported), but I really do not understand the concept of the file you posted here.

    Is there a source for some material to learn about FR? I only can find outdated manuals.
  • edited July 2018
    2 ways to create datasource:
    1. fastreport as standalone, pull data from database with built-in classes
    2. push data from main application (winforms, wpf, web apps) to fastreport

    i attached samples for demonstration:
    1. instagram.frx , standalone report, pull data from internet, a json format, don't forget to copy Newtonsoft.Json.dll into C:\Program Files\FastReports\FastReport.Net Trial, because the dll must exists along with designer.exe
    2. a console project, how to push data to fastreport and custom sort

    basically, two kinds of data object are processed internally by fastreport :
    1. business object (data model or data transfer object, whatever)
    a. if you pushed data from main app with code : report.RegisterData(list, "BODatasource");
    b. you can catch the object from report script : BusinessObjectDataSource data = Report.GetDataSource("BODatasource") as BusinessObjectDataSource;
    c. where is my business object?
        // declare a model in report script:
        class DataModel
        {
            public int? field1 { get; set; }
            public string field2 { get; set; }
        }
    
    and...
        private void _StartReport(object sender, EventArgs e)
        {
          DataSourceBase data = Report.GetDataSource("BODatasource");
          List<DataModel> list = (List<DataModel>)data.Reference;
        }
    

    2. datatable
    a. if you pushed data from main app with code : report.RegisterData(datatable "DataTableDatasource");
    b. you can catch the object from report script : TableDataSource data = Report.GetDataSource("DataTableDatasource") as TableDataSource;
    c. where is my datatable?
        private void _StartReport(object sender, EventArgs e)
        {
          DataSourceBase data = Report.GetDataSource("DataTableDatasource");
          DataTable table = (DataTable)data.Reference;
    
          // custom sort with linq
          // you must set reference to System.Data.DataSetExtensions.dll and System.Core.dll
          DataTable sortedTable = table.Rows.Cast<DataRow>().OrderBy(x => x[0] != DBNull.Value ? x[0] : 1000).CopyToDataTable();
          data.Reference = sortedTable;
        }
    
  • edited 6:40PM
    ipong wrote: »
    2 ways to create datasource:
    1. fastreport as standalone, pull data from database with built-in classes
    2. push data from main application (winforms, wpf, web apps) to fastreport

    i attached samples for demonstration:
    1. instagram.frx , standalone report, pull data from internet, a json format, don't forget to copy Newtonsoft.Json.dll into C:\Program Files\FastReports\FastReport.Net Trial, because the dll must exists along with designer.exe
    2. a console project, how to push data to fastreport and custom sort

    basically, two kinds of data object are processed internally by fastreport :
    1. business object (data model or data transfer object, whatever)
    a. if you pushed data from main app with code : report.RegisterData(list, "BODatasource");
    b. you can catch the object from report script : BusinessObjectDataSource data = Report.GetDataSource("BODatasource") as BusinessObjectDataSource;
    c. where is my business object?
        // declare a model in report script:
        class DataModel
        {
            public int? field1 { get; set; }
            public string field2 { get; set; }
        }
    
    and...
        private void _StartReport(object sender, EventArgs e)
        {
          DataSourceBase data = Report.GetDataSource("BODatasource");
          List<DataModel> list = (List<DataModel>)data.Reference;
        }
    

    2. datatable
    a. if you pushed data from main app with code : report.RegisterData(datatable "DataTableDatasource");
    b. you can catch the object from report script : TableDataSource data = Report.GetDataSource("DataTableDatasource") as TableDataSource;
    c. where is my datatable?
        private void _StartReport(object sender, EventArgs e)
        {
          DataSourceBase data = Report.GetDataSource("DataTableDatasource");
          DataTable table = (DataTable)data.Reference;
    
          // custom sort with linq
          // you must set reference to System.Data.DataSetExtensions.dll and System.Core.dll
          DataTable sortedTable = table.Rows.Cast<DataRow>().OrderBy(x => x[0] != DBNull.Value ? x[0] : 1000).CopyToDataTable();
          data.Reference = sortedTable;
        }
    

    Sorry to bother you again...
    - type "DataTable" does not exist
    - I cannot find any hint how and where to set the mentioned references


  • edited 6:40PM
    learn it from my attachment, full working visual studio project
  • edited 6:40PM
    when starting your project FastReportDataSource it throws Error in FastReport "Main class of report was not found in ReportScript"
  • edited July 2018
    i dont have any clue what you did, works fine for me (visual studio 2017 v15.7.4)
  • edited July 2018
    I am using VS 2015 and VB as script language - but should this be the problem?

    As a workaround I added a datacolumn to my table where all Nulls are converted to 1000 and this works too.

    Something else: is it possible to hide a groupheader conditionally?
    I have a table with "GroupNumber" and "Divider". If Divider=Null then the GroupHeader should not be shown.
  • edited July 2018
    i will prefer your method, adding datacolumn, why?, doing something in script is not optimized because fastreport use reflection to do that, in terms of speed, reflection is slow.

    for reference: https://benohead.com/three-options-to-dynam...te-csharp-code/

    dynamic class is a trade off between speed and flexibility/convenience.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.