Sorting on input fields

Sorting on input fields

SojborgSojborg Posts: 17Questions: 0Answers: 0
edited September 2010 in General
Hey,

I can't sort on input fields from the search box to the top right corner, but if i click on the column header to filter on the column contain the input fields, then i can also use the search box to search data from the input fields.

How can i solve this? There is one problems searching fields which doesn't contain input fields.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Something like this: http://datatables.net/examples/plug-ins/dom_sort.html ?

    Allan
  • SojborgSojborg Posts: 17Questions: 0Answers: 0
    Hey allan,

    Well yes something like that. Its just that i can't sort on the data with the search box. Only if i choose the particular column as asc or desc sorting. Then i can use the search box to search on that column. I would like that i could use the search on every column no matter if they have been checked for sorting.

    Is this possible?
  • SojborgSojborg Posts: 17Questions: 0Answers: 0
    My code looks like this:

    [code]
    jQuery.fn.dataTableExt.afnSortData['input'] = function (oSettings, iColumn)
    {
    var aData = [];
    jQuery('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function ()
    {
    aData.push(this.value);
    });
    return aData;
    }


    dataTypes = jQuery(_target + ' th').map(function (pos, th)
    {
    return { "sSortDataType": jQuery(th).closest('table').find('td:nth-child(' + (pos + 1) + ')').is(':has(input)') ? 'input' : 'html', "bSearchable": true };
    });


    var oTable = jQuery(_target).dataTable({
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "bSort": true,
    "aoColumns": dataTypes,
    "bAutoWidth": true,
    "sScrollY": sEnableScrollY,
    "bScrollCollapse": true,

    }

    });
    [/code]
  • SojborgSojborg Posts: 17Questions: 0Answers: 0
    Is there any thoughts for this?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    I'm afraid I don't understand what you are trying to do - sorry. So search on a particular column, you can use fnFilter. Likewise fnSort can be used to specify a particular sorting ( http://datatables.net/api ).

    Allan
  • SojborgSojborg Posts: 17Questions: 0Answers: 0
    The problem is that i can't search on the values inside a input text box when the datatable is first initialized. If i choose to sort by the column that contains input text boxes then i can search by the text inside the input text boxes.

    Scenario:

    In the table below the Column Name contains input textbox. So Peter, Scott and Hanna texts is shown in textboxes.

    Table
    id Name Address
    1 Peter Petersstreet
    2 Scott Wallstreet
    3 Hanna Montanastreet


    When i initialize the datatable with this data and i try to search by "Peter" notthing shows. I can search by "Petersstreet" and it will the correct data.

    If i then click on the column header "Name" and then search by "Peter" it will find the correct data.

    Does this explain my problem clearer?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Yup - understood now - thanks.

    The reason it works after sorting is the block of code around line 4205 in the current release - the internal data cache (which is used for filtering) is updated during the sort. However, this doesn't explain why it doesn't work for you just after initialisation - the example I linked to above works in this case (search for "1.7" for example). As far as I can see it should work - it won't if you change the value of the input box - you would need to repeat the sort at that point, and perhaps that is all that is needed? Can you point us to a link where this issue is shown please.

    Allan
  • SojborgSojborg Posts: 17Questions: 0Answers: 0
    Thank you for your reply.

    Sorry i don't have a link for this, but i can tell you that in the link you linked you can't search the "Platform" column in Internet Explorer after initialisation. If you click the "Platform" column to sort by it then you can search for for example "Win". This is somehow the same thing that im having problems with. The difference is that i can't search on any input texts and that is the case no matter if i use chrome or ie.
  • SojborgSojborg Posts: 17Questions: 0Answers: 0
    edited September 2010
    The table im using with DataTables is coming from an ajax call, could this havee anything to do with the problem? Maybe its not cached the way DataTables expects it to be, because it is coming form an ajax call?

    Or maybe its the way i make the dataTypes for aoColumns. I posted the code above if you wanna have a look.
  • jcallasjcallas Posts: 6Questions: 0Answers: 0
    I have run into a similar problem. Have tested with both dataTables 1.7.1 and 1.8.2. Table is initialized empty, data is retrieved via ajax call, and then I use the fnAddData(0 method to add it to the table.

    One of my columns contains input elements. When I use the default Search textbox the values of the input elements are not compared. As suggested by Allan a few postings ago, I added the "dom-text" sorting but even after doing that the search continues to not work.

    Any thoughts?
  • sprockettsprockett Posts: 12Questions: 0Answers: 0
    hi any update to this problem?

    Bascially, when u edit text of an inputfield, lets say I change "Mary" to "Bob" in an input field, immediately if i try to search for "Bob", no results show...

    It will only work if i sort that particular columne ONCE. Only then will "Bob" appear.

    This is the case here as well:
    http://datatables.net/examples/plug-ins/dom_sort.html

    If u try editing one of the cells with an input field, and then immediately try to search for that string, it will not appear until u sort that column once.

    Any workarounds?

    Thanks!! :)
This discussion has been closed.