Datatables Editor .NET filter date

Datatables Editor .NET filter date

rauntskarauntska Posts: 5Questions: 2Answers: 0

Hi,

I'm using the .NET version of the editor. I've ran into an issue where i use individual column filtering on a datetime(database) type field.
However it seems that the .NET library generates filtering always by like '%date%'. Is there any way to filter date column ?- Cause this seems not to work like this.

Here-s the code and ajax request

      var request = System.Web.HttpContext.Current.Request;
        using (var db = new Database(ConfigurationReader.GetDatatablesConnectionType(),ConfigurationReader.GetConnectionString()))
        {
            var response = new Editor(db, nameof(EF_NPTIME.LOG),nameof(LOG.ID))
                .Model<LogsModel>()
                .Process(request)
                .Data();

            return Json(response);
        }

draw: 2
columns[0][data]: NPTime_WorkHours.Date
columns[0][name]:
columns[0][searchable]: true
columns[0][orderable]: true
columns[0][search][value]: 07/17/2018
columns[0][search][regex]: false

Thanks

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Hi,

    Yes the typing of the search values is actually quite weak. Some databases will allow that, while some will not (which db are you using)?

    What you might need to do in this case is mark that column as not searchable by the library's default mechanism (columns.searchable) and then use an Editor.Where() call with a lambda expression which would check to see if the value was submitted and if so then apply a condition without the wildcards.

    Thanks for raising this, that is absolutely something that needs to be addressed.

    Allan

  • rauntskarauntska Posts: 5Questions: 2Answers: 0

    Hi,

    Im running MSSQL.
    Yes, thought of your proposed workaround also.
    For future reference, would there be a possibility to add some Dataannotation attibute for the Model properties that is passed into <Model> . That would specify which query to run. For example use the regular equation(=) as the operator instead of the (like'%%')

    [FilterOperator("=")]
    public string Status {get;set;}
    

    Thanks for the reply !

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    That's an excellent suggestion - thanks.

    Allan

This discussion has been closed.