Toolbar search and Datepicker

Oct 24, 2013 at 3:11 PM
Edited Oct 24, 2013 at 3:12 PM
I would like the toolbar search to start when I selected a date from the datepicker.. Now I select the box and the datepicker nicely pops up. I click the date, popup closes, date is correct set in the searchbox but not submitted. As the focus is also removed I have to click back in the textbox, and again the datepicker pops up. If I then press Enter twice it will start the submit..
Can I have something like onchange in the textbox?!

I have set the property like this:
[JqGridColumnSearchable(true, SearchType = JqGridColumnSearchTypes.JQueryUIDatepicker, SearchOperators = JqGridSearchOperators.Eq,DatepickerDateFormat="dd-mm-yy",Delay=100)]

Am I missing a property?!
Coordinator
Oct 24, 2013 at 6:45 PM
What you are experiencing is probably a faulty behaviour due to some subtle bug in the helper (jQuery UI integrations are something that helper adds over standard jqGrid functionality).

I will look into this over the weekend and get back to you.
Oct 24, 2013 at 7:22 PM
I would very grateful if you can find it :-)
Coordinator
Oct 27, 2013 at 9:00 PM
So I can confirm that DatePicker is acting like a text input when it comes to toolbar searching with autosearch set to true. This is correct from jqGrid point of view but from usability point of view it would be better if it act more like select input.

The best workaround at this moment is to create a custom attribute like this;
public class JqGridColumAutoSearchableAttribute : JqGridColumnSearchableAttribute
{
    #region Properties
    protected override IList<JqGridColumnDataEvent> DataEvents
    {
        get
        {
            return new List<JqGridColumnDataEvent>()
            {
                new JqGridColumnDataEvent("change", "function(e) { $('table.ui-jqgrid-btable', $(this).parents('div.ui-jqgrid'))[0].triggerToolbar(); }"),
            };
        }
    }
    #endregion

    #region Constructor
    public JqGridColumAutoSearchableAttribute(bool searchable)
        : base(searchable)
    { }

    public JqGridColumAutoSearchableAttribute(bool searchable, string dataUrlRouteName)
        : base(searchable, dataUrlRouteName)
    { }

    public JqGridColumAutoSearchableAttribute(bool searchable, string dataUrlAction, string dataUrlController) :
        base(searchable, dataUrlAction, dataUrlController)
    { }

    public JqGridColumAutoSearchableAttribute(bool searchable, string dataUrlAction, string dataUrlController, string dataUrlAreaName)
        : base(searchable, dataUrlAction, dataUrlController, dataUrlAreaName)
    { }

    public JqGridColumAutoSearchableAttribute(bool searchable, Type valueProviderType, string valueProviderMethodName)
        : base(searchable, valueProviderType, valueProviderMethodName)
    { }
    #endregion
}
WARNING: This is a little bit of hackery as it strongly depends on jqGrid internals.

The above attribute can be used like this:
[JqGridColumAutoSearchableAttribute(true, SearchType = JqGridColumnSearchTypes.JQueryUIDatepicker)]
public DateTime Date { get; set; }
I will consider building this functionality into the helper in one of future versions, but it requires further investigation in orther to work correctly with internals for every scenario (for example when there is no toolbar searching).
Marked as answer by TPeczek on 11/27/2013 at 2:29 AM
Oct 28, 2013 at 7:23 AM
Thanks for this little hackery !!! It does exactly as I need!

As I don't expect to have searching without toolbar I am happy as it is right now, so thanks again.
Coordinator
Oct 28, 2013 at 11:00 AM
You are welcome, I'm happy I could help.