我有一个包含“位置”字段的类别表。结果将按此字段排序。我希望能够为新行选择一个位置(除了最后一个)。
基本上,表单有一个字段,允许用户选择“之前”或“之后”,然后按位置列出所有类别。表单提交后,应根据选择更新表单。例如,如果有7个现有行,并且用户选择“在5之前”,则应该为新行指定5的位置,然后在此之后更新每一行(包括先前为位置5的行)。如果选择“After 5”,则新行的位置为6,之前为6和7的行将更新为7和8。
有人有什么想法吗?
PS:我在CodeIgniter中这样做(如果你不知道的话),但我很确定逻辑基本相同。
if(count($this->info) > 0)
{
if($this->info['place'] == 0)
{
$new_cat_position = $this->info['where'];
}
else
{
$new_cat_position = $this->info['where'] + 1;
}
$data = array(
'title' => $this->info['title'],
'collapsible' => $this->info['collapsible'],
'position' => $new_cat_position
);
if($this->db->insert('forum_parents', $data))
{
if($this->info['place'] == 0)
{
$this->db->where('position > ', $new_cat_position + 1);
}
else
{
$this->db->where('position > ', $new_cat_position);
}
if(!$this->db->update('forum_parents', $data))
{
$this->error = "The category was created, however, the positions of the other categories were not updated correctly... ".$this->db->_error_message();
}
}
else
{
$this->error = "An unknown system error occurred while processing your request. Please try again later... ".$this->db->_error_message();
}
}
答案 0 :(得分:0)
尝试使用DataTable。它会对你有所帮助。在那个尝试行重新排序功能根据您的要求。
这是链接:
http://code.google.com/p/jquery-datatables-row-reordering/wiki/Index
以下是工作示例:
http://live.datatables.net/onigip/2
一旦能够进行Roe-Reordering,您可以使用某种逻辑更新数据库中的记录。
希望得到这个帮助。