I have the following code which applies the jQuery UI Sortable plugin to all tables (GridView) on an ASP.NET page, excluding the first (header) row in each:
function pageLoad() {
$('table').sortable({
items: 'tr:not(:first)',
axis: 'y',
scroll: true,
start: startDrag, //store start position
stop: stopDrag //get end position, update database
}).disableSelection();
However I only want to apply sortable to a table if there is more than one row (in addition to the header row) otherwise the drag/drop functionality is redundant.
How can I conditionally apply the above only to tables having more than one content row? Thanks.
jquery
filter()provides a solution. It allows you to filter a set of matched elements using a test function. Therefore the following code appliessortableonly to tables that have more than one data row: