tags:

views:

204

answers:

2

I used the jQuery datatable plugin in sort the table data. The sorting works fine if a column contains simple text. If I put any anchor tag condition on a text then the column sorting does not sort properly.

I displayed the values in following manner:

<td><?php if ($allAptArr[$d][27]['staffinactive'] == 1) { ?>
        <?=ucwords(stripslashes($allAptArr[$d][5]['staff_name']));?>
    <?php } else { ?>
        <a href='#' onClick="redirectToStaff('<?=$allAptArr[$d][10]['staff_id']?>');">
        <?=ucwords(stripslashes($allAptArr[$d][5]['staff_name']));?>
        </a>
<?php } ?> </td>

with this code the column sorting fails.

A: 

I think its because your are mixing not anchor with anchor data in the same column. You also shouldn't use onClick, aspecialy with jquery, just setup a click() function with the right selector.

antpaw
A: 

I just had an issue with sorting using datatables when links were involved - I had a column that had links in some cells, and no links in others. It seemed to be sorting, but it was sorting all links and then all non links, as oppose to sorting both links and non links together. The issue turned out to be spacing in the markup. When I took away all non essential spacing around any a tags, my columns sorted perfectly.

aligreene