从前端更改记录的顺序 [英] Changing order of records from the front end

查看:57
本文介绍了从前端更改记录的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编码下一个功能时遇到问题.我希望用户能够重新排列记录并更改display_order值.我正在使用Jquery UI的可拖动和可拖放来简化此操作.

I am faced with a problem coding my next feature. I want the user to be able to rearrange records and change the display_order value. I'm using Jquery UI's draggable and droppable to facilitate this.

我可以看到display_order值的简单交换将如何工作.但是我想为一条记录设置显示顺序,理想情况下是让其他记录随机播放,因此没有重复的display_order值.除了不了解如何做之外,似乎很难编写代码,而且效率低下,将列表中的每个值都改头换面.

I can see how a simple swap of display_order values would work. But I want to set a display order for a record and ideally have the others shuffle around so there are no repeated display_order values. Apart from not getting my head around how I would do that it seems like it would be hard to code and inefficient, shuffling every value around in the list.

因此,我对这种事情的正常情况或应采取的措施持开放态度.

So I am open to other suggestions of how this sort of thing is normally, or should be done.

尽管我可能使用3.000之类的值来表示顺序,然后当我想代替记录时将其值设为3-0.001,因此其值2.999会在2到3之间排序.但是我可以看到这个想法有很多问题,而且似乎不是遵循的好方法.

I though of maybe using a value like 3.000 to represent the order and then when I want to make a record take its place make its value 3 - 0.001 so its 2.999 and will sort between 2 and 3. But I can see so many things wrong with that idea and doesn't seem like a good path to follow.

感谢您的任何输入!

推荐答案

  • 将排序列添加到表smallintmediumintint取决于 预期的总条目数
  • 新条目添加到末尾max(sorting) + 1
  • 在对商品进行重新排序时,获取其将要位于的新位置并相应地更改较高的分类条目:

    • add a sorting column to your table, smallint, mediumint or int depending on the expected number of total entries
    • A new entry is appended to the end, max(sorting) + 1
    • when reordering an item, get the new position it will be in and alter the higher sorting entries accordingly:

      mysql_query('UPDATE yourTable set sorting = '.$yourNewposition.' where id='.$yourUniqueId .' LIMIT 1');

      mysql_query('UPDATE yourTable set sorting = sorting + 1 where sorting >= '.$yourNewposition.' AND id != '.$yourUniqueId );

      这篇关于从前端更改记录的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆