Reputation:
I have a list of article. I filter the list on the client with jquery.
The following function works really fine, the only part is, that the data() would be ignored. the the searchgewerk is per default 0 or got another value which exist in the list.
function filterArticlelist( searchterm, searchgewerk )
{
if(searchterm.length > 1) {
if( searchgewerk == 0 )
{
var match = $( 'tr.data-row:contains("' + searchterm + '")' );
var nomatch = $( 'tr.data-row:not(:contains("' + searchterm + '"))' );
}
else
{
//When searchgewerk is not 0 then i reach this else part. With console.log() the correct searchgewerk value would be logged.
var match = $( 'tr.data-row:contains("' + searchterm + '")').data( "gewerk",searchgewerk );
var nomatch = $( 'tr.data-row:not(:contains("' + searchterm + '"))' ).data( "gewerk",searchgewerk );
}
match
.addClass( 'selected' )
.css( "display", "" );
nomatch
.css( "display", "none");
}
else
{
$('tr.data-row').css("display", "");
$('tr.data-row').removeClass('selected');
}
}
Where is my error? Maybe did i think in a wronk way? I have also tried hasData(), but it also doesent work.
Thanks for your help
This is the view for every tr, its build with TWIG:
{% for data in ObjektArtikel %}
{% if loop.index0 is not even %}
{% set background = "trAvailableArticleBackground" %}
{% else %}
{% set background = "trAvailableArticleNoneBackground" %}
{% endif %}
<tr class="data-row trAvailableArticle {{ background }}" id="{{ data.artikelnummer }}" data-gewerk="{{ data.su_gewerk }}">
<td class="tdArticleNumber">
{{ data.artikelnummer }} - {{ data.su_gewerk }}
</td>
<td class="tdArticle">{{ data.artikel }}</td>
<td class="tdArticleDescription">{{ data.beschreibung }}</td>
<td class="tdArticleEinheit">{{ data.einheit }}</td>
<td><img class="addArticle" src="/bundles/mbsallgemein/images/add.png"></td>
</tr>
{% endfor %}
Upvotes: 0
Views: 93
Reputation: 27012
If you're trying to filter on the data-gewerk
attribute, you may be looking for something like this:
$('tr.data-row[data-gewerk="' + searchgewerk + '"]:contains("' + searchterm + '")')
This:
.data(key, value)
is a setter, it doesn't filter anything.
Upvotes: 0