Input fields appended at the end of search field

Input fields appended at the end of search field

ManroManro Posts: 4Questions: 0Answers: 0
edited November 2010 in General
I have added some input fields to capture date and treat as regex info for server side processing. However, the values for all input fields gets reset to the value of the search input field. Could I change this behavior? Is there a more optimum way to implement a more advanced search?

Thanks,

Manro

Replies

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    You can pass custom parameters which can be used for advanced search using the method shown in this example: http://datatables.net/examples/server_side/custom_vars.html .

    Allan
  • ManroManro Posts: 4Questions: 0Answers: 0
    Hi Allan,

    Firstly, great work. It has served us quite well.

    I am passing custom parameters. I have appended a button to the right of the Search field. Clicking on this button launches an advanced search dialog which allows users to enter dates and regular expressions.

    The issue I am running into is if I enter anything in the default search field, that value gets set as the value of the button. So if I search for "test", as the results are returned, the word "test" appears on top my advanced search button on the right.

    Any ideas?

    Manro
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    I'm not sure I understand this bit: "that value gets set as the value of the button". What is setting the value of what button? Is this a custom element and control you've put into the table? Can you give us a link?

    Allan
  • ManroManro Posts: 4Questions: 0Answers: 0
    [code]
    // Add advanced search button next to search field
    $('#div_event_logs .dataTables_filter').append('');
    $('#advSearch').click(function() {
    advancedSearchOpenClose();
    });
    [/code]

    This is what I did to add a button element next to the Search input box.

    Now if I search for 'test', the value attribute of the button also gets set to 'test'

    [code]

    Search:

    [/code]

    Does that make sense? Unfortunately, I don't have a link to share.
  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin
    Ah yes - I see what you mean. The problem is this line in DataTables:

    [code]
    $('input', n[i]).val( this.value );
    [/code]
    Line 3991 in the version which is up-to-date on github.

    This is setting all 'input' elements to have a value of the input. The answer is simply to add :eq(0) to the selector... I'm wondering if this is the right thing to do though, since you could just as easily have used insertBefore which would break this is a different way... I guess one answer is to add a class... I'll have a think about it!

    Allan
  • ManroManro Posts: 4Questions: 0Answers: 0
    I actually got around the problem for now by setting my button color transparent.

    [code]
    input#advSearch {
    float: right;
    margin-top: 1px;
    color: transparent;
    }
    [/code]

    I am always reluctant to change anything in the jQuery and jQuery.plugin files, since stuff breaks in the event of an upgrade to a newer version.

    Anyway, keep up the good work.
  • antiplastikantiplastik Posts: 4Questions: 0Answers: 0
    Subscribing.

    Indeed a class and a more specific selector would be great. I have the exact same issue when trying to add two stupid "Submit" and "Reset" buttons :-)

    -- Oh, while writing this, I'm just thinking, why not inserting text instead of buttons? This is a good workaround :-)
This discussion has been closed.