I want to skip 2 tr in the table with 2 different classes.
first tr with class is .gridTitleRow and 2nd tr with class is .gridSpan . How to skip these in below syntax?
$.each($(".gridTable tr:not(.gridTitleRow)"), function(a, b){});
EDITED I am using each like below
$("#gridBtn").live("click", function (e) {
e.preventDefault();
var indexArraay = [];
var flag = false;
$.each($(".gridTable tr:not(.gridTitleRow)"), function(a, b){
var id = $("input.idField", b).val();
var order = $("input[id='index']", b).val();
var active = $("input[id='activeCb']", b).attr("checked");
var deleteRow = $("input[id='deleteCb']", b).attr("checked");
(deleteRow == true) ? flag = true : null;
indexArraay.push({
"id": id,
"index": order,
"active": active,
"delete": deleteRow
})
});
if (flag == true)
{
$("#dialog:ui-dialog").dialog("destroy");
var text = "Alert: Deleting footer Prent menu will delete all submenus and assigned pages to it.";
$('<div title="Confirmation:">' + text + '</div>').dialog({
height: 'auto',
width: 350,
modal: true,
resizable: false,
buttons: {
Cancel: function () {
$(this).dialog("close");
},
Confirm: function () {
$(this).dialog("close");
ProcessGrid(indexArraay);
ReloadGrid();
}
}
});
}else{
ProcessGrid(indexArraay);
//ReloadGrid();
}
}); //End of gridBtn
Table
<script id="gridTemplate" type="text/x-jQuery-tmpl">
<tr class="gridRow">
<td class="gridSpan" colspan="5">${$data[0].Title}</td>
</tr>
{{tmpl($data) "#cellTemplate"}}
</script>
<script id="cellTemplate" type="text/x-jQuery-tmpl">
<tr class="gridRow">
<td class="cellTd ">
<input type="checkbox" id="deleteCb" />
<input type="hidden" id="Id_ + ${num}" class="idField" value="${Id}" />
</td>
<td class="cellTd">
<input id="index" name="index" class="numberField" type="text" value="${IndexOrder}" />
</td>
<td class="cellTd">${DisplayName}</td>
<td class="cellTd ">${UrlName}</td>
<td class="cellTd ">
<input type="checkbox" id="activeCb" {{if Active}} checked{{/if}} />
</td>
</tr>
</script>
<span class="instructions">Only numeric value is allowed in IndexOrder textbox.</span>
<div class="gridDiv">
<table class="gridTable" cellspacing="0" cellpadding="0">
<tbody>
<tr class="gridTitleRow">
<td class="iconLink width36">Delete</td>
<td class="iconLink width60">Sort Order</td>
<td class="iconLink widthAuto">Display Name</td>
<td class="iconLink widthAuto">Url Name</td>
<td class="iconLink widthAuto">Active</td>
</tr>
</tbody>
</table>
In selectors, the “,” is like “or”.
Wait – it’s like “and”, but because your selector here is in a “not()” clause, it’s “not this one and not that one”, which is like “not (this one or that one)”.I think I may belabor the point a bit 🙂edit — no I convinced myself it’s “or” again. Need coffee.
edit again — a couple things:
There’s no reason to call “$.each()” when the first object is already a jQuery object:
When searching by “id” value, there’s no reason to use an attribute selector, and there’s no reason to use a context because “id” values must be unique. Use “#id”:
Please note again that it is invalid to use the same “id” value for multiple elements on a page. If you’re using the same “id” on many table rows, that is wrong and you’ll have to change it.
The jQuery team has deprecated the form
$(selector, base)and prefer the form$(base).find(selector). Internally, the library always performs that transformation, so you might as well save it the trouble:It’s not at all clear what “flag” is supposed to do, but you may have forgotten to declare it. Maybe it’s a global variable.
Your comment says that “empty tr is passing with undefined”, but I do not know what that means. If the selector finds no
<tr>elements, the “each” loop will simply not happen. If you describe what exactly it is that’s undefined, it might be possible to help.