首页 文章

在Telerik Radgrid上拖动重新排序

提问于
浏览
0

我试图在我的radgrid上使用拖动重新排序 . 我的代码很适合我(它在RowDrop事件上触发)但我的客户端无法使它工作,我已经解决了它以显示当他执行drop时,args的DestDataItem属性为null,因此丢弃逻辑永远不会触发?!?这是我的代码:

protected void questionGrid_RowDrop(object sender, GridDragDropEventArgs e)
    {
        if (e.DestDataItem != null)
        {
            int tempId = int.Parse(editingId.Value);
            theTemplate = ent.SurveyTemplates.Where(i => i.Id == tempId).FirstOrDefault();
            int id = int.Parse(e.DraggedItems[0]["Id"].Text);
            SurveyQuestion draggedQuestion = ent.SurveyQuestions.Where(i => i.Id == id).FirstOrDefault();
            List<SurveyQuestion> tempArray = theTemplate.Questions.OrderBy(i => i.Rank).ToList();
            tempArray.Remove(draggedQuestion);
            tempArray.Insert(e.DestDataItem.ItemIndex, draggedQuestion);
            int j = 0;
            foreach (SurveyQuestion sq in tempArray)
            {
                sq.Rank = j;
                j++;
            }
            ent.SaveChanges();
            questionGrid.Rebind();
        }
        else
        {
            Exceptions.LogException(new Exception("NULL DEST"));
        }
    }

它只引用拖动的项目并从项目列表中拉出它并在新索引处重新插入它,然后它将每个项目的rank属性更新为其新索引并保存 .

为什么这对我而言不适合他?这个服务器端代码是否会受到浏览器差异的困扰?

1 回答

  • 1

    this thread中所述,如果项目未被删除到网格中的实际数据行,则DestDataItem将为null .

    如果目标不是数据行,则可以通过处理客户端上的OnRowDropping事件并忽略您不想要的内容来阻止您的RowDrop事件触发:

    function gridRowDropping(sender, args)
    {
        if (!args.get_targetGridDataItem())
            args.set_cancel(true);
    }
    

相关问题