简体   繁体   中英

dynamically generated table does not behave as datatable after AJAX call

I have dynamically generated table in PHP but in response this table is not being created as datatable even i have used datatable plugin in file.

I have also one table that is generated on the page ready event with same schema and it has datatable behaviour.

so whats problem with dynamically generated table?

Plz Help

Thanks.

My code is as below :

ajax.php

$projectArr=$database->select("odeskuserdetails","OdeskUserId,UserName","IsDeleted=0"); $grand=0; for($i=0;$i<count($projectArr);$i++){ $query="SELECT count(JobStatusId) as count from jobstatus where CreatedDate BETWEEN '".$_REQUEST['dateFrom']."' AND '".$_REQUEST['dateTo']."' and StatusId=3 and UserId in (SELECT UserId FROM odsekuserassignment where OdeskUserId =".$projectArr[$i]['OdeskUserId'].")"; $result= mysql_query($query); $row= mysql_fetch_array($result); $k=$i+1; $projectArr[$i]['Sr.No.']=$k; $projectArr[$i]['Total Jobs']=$row['count']; $grand +=$row['count']; } // Sort the array by Total Jobs. usort($projectArr, function ($a, $b) { return ($b['Total Jobs'] - $a['Total Jobs']); }); // Table Creation Starts : echo '<table id="table2" class="tablesorter table table-bordered table-condensed table-hover table-striped" > <thead> <tr> <th><center>Sr. No.</center></th> <th><center>Odesk Account</center></th> <th><center>Total Jobs Applied</center></th> </tr> </thead> <tbody>'; if(is_array($projectArr)) { $cval='0'; foreach ($projectArr as $data) { if (!is_array($data)) { if($cval=='0') { $cval ='1'; echo '<tr class="allPrjRow">'; echo '<td><center>'.$projectArr["Sr.No."].' </center></td>'; echo '<td><center>'.$projectArr["UserName"]. '</center></td>'; echo '<td><center>'.$projectArr["Total Jobs"].'</center></td>'; echo '</tr>'; } } else { echo '<tr class="allPrjRow">'; echo '<td><center>'.$data["Sr.No."].'</center></td>'; echo '<td><center>'.$data["UserName"].'</center></td>'; echo '<td><center>'.$data["Total Jobs"].'</center></td>'; echo '</tr>'; } } echo '</tr>'; // print_r($x); } echo '</tbody> </table> <div id="gtotal" style="float: right;margin-right: 200px;">Grand Total :'.$grand.'</div>';

It depends on where you have put your code snippet. Place the code which creates dynamic table at the end,when all the js gets loaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM