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

Add an option to set the icon's content based on order #1352

Closed
wants to merge 1 commit into from

Conversation

timoschwarzer
Copy link

@timoschwarzer timoschwarzer commented Jan 30, 2017

This is useful for e.g. Material icon font, where you have to write <i class="material-icons">arrow_downward</i>

This is useful for e.g. Material icons, where you have to write <i class="material-icons">arrow_downward</i>
@Mottie
Copy link
Owner

Mottie commented Jan 31, 2017

Hi @timoschwarzer!

Thanks for your contribution!

As much as I love having tons of options, I don't think these three new ones are necessary...

CSS (along with Materialize)

.tablesorter-header .material-icons {
  font-size: 20px;
  position: absolute;
  right: 2px;
  top: 50%;
  margin-top: -.5em;
}

Script

$.tablesorter.addWidget({
  id: 'material-icons',
  options: {
    icon_text: {
      asc: "keyboard_arrow_up",
      desc: "keyboard_arrow_down",
      unsorted: "format_line_spacing"
    }
  },
  format: function(table, c, wo) {
    var icon = "." + c.cssIcon;
    c.$headers.find(icon).text(wo.icon_text.unsorted);
    $.each(c.sortList, function(indx, val) {
      var dir = val[1] === 0 ? 'asc' : 'desc';
      c.$headers.eq(val[0]).find(icon).text(wo.icon_text[dir]);
    });
  }
});

$(function() {
  $("table").tablesorter({
    theme: "materialize",
    widthFixed: true,

    // add material icons to headers
    headerTemplate: "{content}{icon}",
    cssIcon: "material-icons",

    // widget code contained in the jquery.tablesorter.widgets.js file
    // use the zebra stripe widget if you plan on hiding any
    // rows (filter widget)
    widgets: ["filter", "zebra", "material-icons"],

    widgetOptions: {
      // using the default zebra striping class name, so it actually
      // isn't included in the theme variable above; this is ONLY
      // needed for materialize theming if you are using the filter
      // widget, because rows are hidden
      zebra: ["even", "odd"],
      // reset filters button
      filter_reset: ".reset",
      // extra css class name (string or array) added to the filter
      // element (input or select); select needs a "browser-default"
      // class or it gets hidden
      filter_cssFilter: ["", "", "browser-default"]
    }
  });
});

@timoschwarzer
Copy link
Author

@Mottie
I didn't know/realize that this is possible with a custom widget. Thank you very much for your helpful demo!

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

Successfully merging this pull request may close these issues.

None yet

2 participants