Domanda

i have an alphabetical menu. and problem is that data is showed in one long list at the beginning, and just after clicking on some Letter it will be showed under groups.

FALSE at the pageload.

i need to have it already splitted in groups like this (happens after click on A or B)

and here is my function

$(function () {

            debugger;
            var _alphabets = $('.alphabet > a');
            var _contentRows = $('#countries-table tbody tr');

            _alphabets.click(function () {
                var _letter = $(this), _text = $(this).text(), _count = 0;

                _alphabets.removeClass("active");
                _letter.addClass("active");

                _contentRows.hide();
                _contentRows.each(function (i) {
                    var _cellText = $(this).children('td').eq(0).text();
                    if (RegExp('^' + _text).test(_cellText)) {
                        _count += 1;
                        $(this).fadeIn(400);
                    }
                });
            });
        });
È stato utile?

Soluzione

You just need to manually trigger .click() event, you can do that on the first element:

_alphabets.click(function () {
    //...
});

//trigger manually:
_alphabets.first().trigger("click");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top