首页 > 解决方案 > 在数据表中拖放在下一页上不起作用正确的位置在数据库中没有更新

问题描述

我正在对数据表使用拖放 jquery 代码。当移动到下一页时,我的第一行拖放(1)10 个记录器在数据表中正常工作第二(2)它不能正常工作。在数据表行的第二页上没有正确拖放,并且在数据库位置列中没有正确更新其使列位置在第二页上的值为 1。我现在的问题是如何在所有页面上更新数据表中的位置列第一,第二,第三等等......

我试图改变位置 $value['position'] = ('$pages_row * $page_size) + $key

<script>
         $(document).ready(function() { 
  var $sortable = $( "#athlete-class-datatable-responsive > tbody " );

  $sortable.sortable({
      stop: function ( event, ui ) {
          var parameters = $sortable.sortable( "toArray" );
           alert(parameters);
           var url = '/godspeed/Athlete_class/updatePositions';
          $.post(url,{value:parameters},function(result){
              alert(result);
          });
      }
  });
  });
</script>

控制器

  public function updatePositions() {  
foreach ($_POST["value"] as $key => $value) {          
     $data["position"] = $key; // i am unable to change position on next page 
       $this->Athlete_classes->updatePosition($data,$value);
     }
echo "Sorting Done";
 }

模型

function updatePosition($data,$id){
    if(array_key_exists("from", $data)){
        $data["from"]=$this->real_escape_string($data["from"]);
    }
    foreach ($data as $key => $value) {
        $value="'$value'";
        $updates[]="$key=$value";
    }
        $imploadAray =  implode(",", $updates);
                  $query=$this->db->query("Update dev_athlete_class SET $imploadAray Where id='$id'");
}

我的html代码是

<table class="table table-bordered table-striped" id="athlete-class-datatable-responsive"> 
                    <!--<table  id="athlete-class-datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap bulk_action" cellspacing="0" width="100%">-->
                        <thead>
                            <tr>
                                <th class="no-sort" style="width: 30px;" ><input type="checkbox" id="check-all" class="flat check_all" data-check="athlete_class_list" ></th>
                               <th>id</th>
                                <th>Position</th>
                                <th>From Time</th>
                                <th>To Time</th>
                                <th class="no-sort" style="width: 50px;text-align: center;" >Edit</th>
                            </tr>
                        </thead>

                        <tbody>
                            <?php foreach ($data['Exercise_multiplier_datas'] as $key => $value) { ?>
                                <!--<tr>-->
                           <tr id="<?php echo $value["id"]; ?>">
                                    <td style="vertical-align: middle;"><input type="checkbox"    id="<?php echo $value['id']; ?>" class="flat athlete_class_list multiple_delete"></td>
                                    <td><?php echo $value["id"]; ?></td>
                                    <td><?php echo $value["position"]; ?></td>
                                    <td style="vertical-align: middle;"><?php echo $value['from']; ?></td>
                                    <td style="vertical-align: middle;"><?php echo $value['to']; ?></td>
                                    <!--<td style="width:4%"><img src="<php echo  base_url() ?>assets<php echo $value['image']; ?>" class="user_image_athlete_level_image" style="width:70px;height:70px"></td>-->
                                   <td style="text-align: center;vertical-align: middle;"><a href="#/pencil-square-o" class="edit_Athlete_class option_icon" data-json='<?php echo htmlspecialchars(json_encode($value, TRUE), ENT_QUOTES, 'UTF-8'); ?>'  data-block="school_form_block" data-form="school_form" ><i class="fa fa-edit"></i></a></td>

                                  <input type="hidden" value="<?php echo $value["id"]; ?>" id="item" name="item">
                                </tr> 
                             <?php } ?>

                        </tbody>


                    </table>

我的数据表就像 sencod 页面上的那样,它的显示位置 id 10 相同的 id 显示

id | from    | to    | position 
1    18:00    19:00      1
2    20:00    21:00      2
3    18:00    22:00      3
4    12:00    23:00      4
5    18:00    24:00      5
6    12:00    25:00      6
7    18:00    26:00      7
8    12:00    27:00      8
9    18:00    28:00      9
10   12:00    29:00      10
11   18:00    19:00      1
12   12:00    01:00      2

我想要一个具有当前位置 id 的数据表中的实际结果

id | from    | to    | position 
1    18:00    19:00      1
2    20:00    21:00      2
3    18:00    22:00      3
4    12:00    23:00      4
5    18:00    24:00      5
6    12:00    25:00      6
7    18:00    26:00      7
8    12:00    27:00      8
9    18:00    28:00      9
10   12:00    29:00      10
11   18:00    19:00      11
12   12:00    01:00      12

标签: phpjquery

解决方案


推荐阅读