gpt4 book ai didi

jquery - 有没有办法使用 gridDnD 插件将行从 JQGrid 拖动到可放置文本字段?

转载 作者:行者123 更新时间:2023-12-03 23:04:46 26 4
gpt4 key购买 nike

我想将一行从 JQGrid 拖动到文本输入字段,并将列的文本从拖放的行添加到输入中文本的末尾。

显然,这与答案相去甚远,但是从设置了此设置的网格中拖动一行(其中 #inputTextField 是“可放置”文本字段)会导致 JavaScript 错误this.p 未定义:

$("#searchResultsGrid").jqGrid('gridDnD',
{
connectWith: '#inputTextField"
}
);

这是因为目标显然不是 JQGrid 并且没有定义 this.p 。我尝试了一些不同的事情......也许有一种方法可以“欺骗”放置事件以使其工作?非常感谢您的帮助:)

最佳答案

我明白了!!首先,使网格行可拖动(应在 gridComplete 网格事件处理程序中调用此函数):

function makeGridRowsDraggable() {

var $searchResultsGrid = $("#searchResultsGrid"),
$searchResultsRows = $("#searchResultsContainer .ui-row-ltr");

$searchResultsRows.css("cursor","move").draggable("destroy").draggable({
revert: "false",
appendTo: 'body',
cursor: "move",
cursorAt: {
top: 10,
left: -5
},
helper: function(event) {

//get a hold of the row id
var rowId = $(this).attr('id');

//use the row id you found to get the column text; by using the getCell method as below,
//the 'unformatter' on that column is called; so, if value was formatted using a
//formatter, this method will return the unformatted value
//(as long as you defined an unformatter/using a built-in formatter)
var theValue = $searchResultsGrid.jqGrid('getCell', rowId, 'desiredValue');

//set the data on this to the value to grab when you drop into input box
$(this).data('colValue', theValue);

return $("<div class='draggedValue ui-widget-header ui-corner-all'>" + theValue+ "</div>");
},
start: function(event, ui) {
//fade the grid
$(this).parent().fadeTo('fast', 0.5);
},
stop: function(event, ui) {
$(this).parent().fadeTo(0, 1);
}
});
}

然后,创建可放置元素:

function createDroppableElements() {

$("#inputFieldOne, #inputFieldTwo").droppable({
tolerance: 'pointer',
hoverClass: 'active',
activate: function(event, ui) {
$(this).addClass("over");
},
deactivate: function(event, ui) {
$(this).removeClass("over");
},

drop: function(event, ui) {
var theValue = ui.draggable.data('colValue');
theValue = theValue .replace(/<br>/gi,'; ');
console.log("dropped value: " + theValue );

updateText($(this), theValue);
}
});
}

创建一个辅助方法以将文本附加到文本字段(附加尾随“;”):

function updateText(txtTarget, theValue) {

var currentValue = txtTarget.val().trim();

if (currentValue.length > 0
&& currentValue.substr(currentValue.length-1) !== ";")
currentValue = currentValue + '; ';

currentValue += theValue;


txtTarget.val(currentValue);
}

关于jquery - 有没有办法使用 gridDnD 插件将行从 JQGrid 拖动到可放置文本字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9105559/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com