jQWidgets Forums

jQuery UI Widgets Forums Grid Filtering with custom sortFunction: Focus from control lost

This topic contains 16 replies, has 2 voices, and was last updated by  Peter Stoev 11 years ago.

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author

  • rajamalik
    Participant

    Hello,

    We have implemented a grid with custom sort function(eg. sortFunction)

    and we have assigned it to source as:

    source.sort = sortFunction;

    Grid is also filterable, hence filterable : true;

    Now, in my sortFunction the last line of code is:

    $(element).jqxGrid('updatebounddata', 'sort'); //this is to repaint the grid and telling the purpose is sorting.

    Filtering is working fine but I loose focus from the textbox which I use to filter data. It is apparent that the call to updatebounddata with sort parameter is the culprit. Because when I remove it then I do not loose the focus from the textbox. But if I remove the updatebounddata call with sort param then sorting does not work which is also obvious as grid will not refresh.

    I have also tried other parameters like filter, data, cell and <blank>. Nothing works to retain the focus on the textbox.

    My questions are:
    1. Why the grid is calling sort function when filtering the data.
    2. Is it neccessary to call sort function when filtering is called.
    3. What is the way to code so that sortFunction should not be called when we filter the data.

    Thanks
    Raja


    Peter Stoev
    Keymaster

    Hi Raja,

    $(element).jqxGrid(‘updatebounddata’, ‘filter’); should be called in case of filtering.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    rajamalik
    Participant

    Hello Peter,

    As mentioned in my post, I have already tried all the possible parameters to updatebounddata but it is not working.

    Request you to go through my post again and answer the following questions:
    1. Why the grid is calling sort function when filtering the data.
    2. Is it neccessary to call sort function when filtering is called.
    3. What is the way to code so that sortFunction should not be called when we filter the data.

    Thanks
    Raja


    Peter Stoev
    Keymaster

    Hi Raja,

    1. The Grid will call sort if it is necessary and you have already sorted Grid.
    2. same as #1.
    3. It won’t be called unless you already have sorting applied.

    Btw. you can look at: http://www.jqwidgets.com/jquery-widgets-demo/demos/php/serverfiltering_paging_and_sorting.htm?arctic which implements custom sorting & filtering in one Grid.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    rajamalik
    Participant

    Thanks for your response. I looked into the example you provided and please confirm my understanding:

    My understanding is, if we write custom sort function then we should also write custom filter function and with in that we need to call updatebounddata with filter parameter.

    Do you also have an example of custom sort with filter row?

    Thanks
    Raja


    rajamalik
    Participant

    What I mean is that, I have gone through the example of custom filtering

    I understood everything but how will I get hold of column in which I am typing in order to filtering to happen. Remember I am using filter row.

    So, If the filter row is visible and we have textbox for two columns First Name and Last Name, how will I come to know which column I am typing in to filter.

    Thanks
    Raja


    Peter Stoev
    Keymaster

    Hi Raja,

    It does not matter whether it is Filter Row or Filter Menu. The Filtering API is the same. However, we do not have such example.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    rajamalik
    Participant

    Ok Peter. so to conclude this –

    1. I have to implement the filter function by myself.
    2. Implement custome filter when implementing custome sorting.

    Please confirm this.

    BTW, do you have source code of the example you provided. It will be really helpfull if you have one.
    Thanks
    Raja


    Peter Stoev
    Keymaster

    Hi Raja,

    1. The example is included in the download package. In addition, its source code is available online. You can view it in the View Source tab or you can just right-click on the page and click View page Source, too.
    2. I have not written that you have to implement the filter or sort function by yourself. That is your own choice. If you do not want to use the built-in local filtering and sorting, then you can implement it. Otherwise, use the built-in functionality.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/


    rajamalik
    Participant

    Peter, sorry for that but you are confusing me.

    Built in filter functionality is fine but the problem is that because we have custom sort function, built in filter function calls my sort function and the focus goes away from the control.

    So, we are back to the originally asked question:
    If we have implemented custom sort function, then how do we keep the focus on control in tact while filtering?

    Peter, can’t we discuss this over call?
    Thanks
    Raja


    Peter Stoev
    Keymaster

    Hi Raja,

    We do not provide phone support. “updateboundatata” with “filter” param should be called in case of filtering. “updatebounddata” with “sort” param should be called in case of sorting. Sorting will be performed only in case you Filter already sorted Grid.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    rajamalik
    Participant

    Thanks for your support and patience.


    rajamalik
    Participant

    Peter,

    I have found a way with which we can focus the textbox in filter row. We capture the filter event which is fired after the firtering has happened and with the help of the event which is passed to the handler, we write:

    $(element).on('filter', function(event) {
          event.args.owner.focusedfilter.focus();
    });

    But this works alternatively, can you please provide some input on this. Please this is urgent.

    Thanks
    RAJA


    rajamalik
    Participant

    Ok, got it why it is working every second time. I tried to get hold of id of the input box and tried something like:

    $(element).on('filter', function(event) {
                        var xid = $(event.args.owner.focusedfilter).attr('id');
                        console.log(xid);
                        $('#'+xid).focus();
                    });

    The console log printed this:

    2 jqxWidgetd3a24628 Grid.js?version=8.0.0.8.0.0:523
    2 jqxWidget80477522 Grid.js?version=8.0.0.8.0.0:523
    jqxWidget485ec106 Grid.js?version=8.0.0.8.0.0:523

    So, the ids when found duplicate, focus does not work. The number 2 in the above console log show that there are 2 elements with same ids. For the third id, which is unique, focus does gets back to the input box.

    Can you please give me some idea why it is doing that way? As far as I know, whole grid is reconstructed so does the input box. Hence we should always get uniquely generated ids, isn’t it?


    Peter Stoev
    Keymaster

    Hi rajamalik,

    There is no public API about focusedfilter and that means that the provided code is some “hack” which you try to implement for some reason. Yes, the Grid generates unique IDs for its filters.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic.