Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name attribute of inputs in filter #1499

Closed
pierresh opened this issue Jan 24, 2018 · 2 comments
Closed

Name attribute of inputs in filter #1499

pierresh opened this issue Jan 24, 2018 · 2 comments

Comments

@pierresh
Copy link

pierresh commented Jan 24, 2018

Hello,

I think it would be very useful to have the ability to set the name attribute of inputs in filters (I am using Tablesorter with ajax calls). I think this could be set like this (similar to initialization of values):

<th data-name='my_name_attribute'>Field 1</th>

I just made some tests in jquery.tablesorter.widgets.js, the code below does the job but that is probably not the cleanest way to achieve it.

buildFilter = $( '<input type="search">' ).appendTo( $filter );

/* My modification is below: */
if ($(table).find('thead tr:first th').eq(column).data('name') != undefined) {
	buildFilter.attr('name', $(table).find('thead tr:first th').eq(column).data('name'));
}

Thanks

@Mottie
Copy link
Owner

Mottie commented Jan 24, 2018

Hi @pierresh!

You can create your own custom filter row (demo), or add the name attribute within a callback bound to the filterInit event:

Custom HTML Row:

<tr class="tablesorter-ignoreRow filters">
  <!-- the `data-column` attribute in the input is mandatory -->
  <td><input name="foo" type="search" data-column="0" /></td>
  <td><input name="bar" type="search" data-column="1" /></td>
  ...
</tr>

Script

$(function() {
  $("table").tablesorter({
    theme: "blue",
    widgets: ["zebra", "filter"],
    widgetOptions: {
      filter_columnFilters: false,
      filter_external: "tr.filters input"
    }
  });
});

@pierresh
Copy link
Author

Hi @Mottie ,

Thanks a lot for your prompt reply, this works perfectly 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants