EasyUI彈出框行編輯如何通過下拉框?qū)崿F(xiàn)內(nèi)容聯(lián)動(dòng)
EasyUI彈出框行編輯,通過下拉框?qū)崿F(xiàn)內(nèi)容聯(lián)動(dòng)
需求
實(shí)現(xiàn)用戶支付方式配置,當(dāng)彈出框加載出來的時(shí)候,顯示用戶現(xiàn)有的支付方式,datagrid的第一列為conbobox,下來選擇之后實(shí)現(xiàn)后面的數(shù)據(jù)直接填充;

點(diǎn)擊新增:新增一個(gè)空白行
選擇結(jié)算條款編碼:后面的結(jié)算方式等信息自動(dòng)帶出來
點(diǎn)擊刪除:此行刪除
實(shí)現(xiàn)
html代碼(只列舉彈出框部分)
<div class="easyui-dialog" id="configDialog" title="客戶條款配置" style="width: 800px;height:400px; padding:2px 2px;" data-options="
iconCls:'icon-save',
closed : true,
modal: true,
maximizable:true,
onResize:function(){
$(this).dialog('center');
},
buttons: [{
text:'保存',
iconCls:'icon-ok',
handler:function(){
alert('ok');
}
},{
text:'取消',
iconCls:'icon-no',
handler:function(){
$('#configDialog').dialog('close');
}
}]
">
<div>
<table style="width:100%;height:322px;" id="configTable" class="easyui-datagrid"
data-options="singleSelect:true,selectOnCheck:true,checkOnSelect:true,fit:false,striped:false,autoRowHeight:false,pagination:false,
toolbar: [{
text:'新增',
iconCls:'icon-add',
handler:function(){
appendRow();
}
}]
">
<thead>
<tr>
<th field="id" checkbox="true"></th>
<th data-options="field:'code',editor:{
type:'combobox',
options:{
valueField:'id',
textField:'code',
url:'${ctx}/json/PoPaymentJsonController/getAllTipsList',
onSelect: refreshRow
}
}" width="150" >結(jié)算條款編碼</th>
<th data-options="field:'settlementTypeName'" width="150" >結(jié)算方式</th>
<th data-options="field:'startTypeName'" width="150" >結(jié)算起始日期</th>
<th data-options="field:'period'" width="150" >結(jié)算天數(shù)</th>
<th data-options="field:'remark'" width="100" formatter="detailFormatter">操作</th>
</tr>
</thead>
</table>
</div>
</div>JS代碼
<%-- 配置 --%>
function config(index){
const row = $('#dg').datagrid('getRows')[index]
const queryParams = {id:row.id}
$("#configTable").datagrid({
url : '${ctx}/json/PoPaymentJsonController/queryCustomerPaymentConfigMap',
queryParams : queryParams
});
$('#configDialog').dialog('open')
}
<%-- 添加一行 --%>
function appendRow(){
let dg = $('#configTable');
dg.datagrid('appendRow',{code:'',settlementTypeCode:'',startTypeCode:'',period:''});
// 獲取新增的行的索引
let index = dg.datagrid('getRows').length - 1;
dg.datagrid('beginEdit', index);
}
<%-- 刪除一行 --%>
function deleteRow(index){
let dg = $('#configTable');
let row = dg.datagrid('getRows')[index];
if(row.id){
deleteRows.push(row)
}
dg.datagrid('deleteRow', index);
}
<%-- 填充行 --%>
function refreshRow(row){
console.log('row',row);
// 使用closest方法向上查找最近的td元素
let $table = $(this).closest('table');
// 獲取td
let $td = $table.closest('td');
$td.click();
const dg = $('#configTable');
const selected = dg.datagrid('getSelected');
const rowIndex = dg.datagrid('getRowIndex',selected);
// dg.datagrid('endEdit', rowIndex);
// dg.datagrid('updateRow',{
// index:rowIndex,
// row:row
// });
dg.datagrid('deleteRow',rowIndex);
dg.datagrid('insertRow',{
index:rowIndex,
row:row
})
}難點(diǎn)解析
當(dāng)點(diǎn)擊選中下拉框之后需要更新當(dāng)前行,但是經(jīng)過測(cè)試,使用datagrid的onClickRow或者是onClickCell均不起作用,原因就是我們點(diǎn)擊的是單元格中的元素
解決思路
1、通過F12中查看dom結(jié)構(gòu),然后獲取到原本datagrid的td元素;
2、通過td的點(diǎn)擊事件結(jié)合datagrid的selectOnCheck:true,checkOnSelect:true 使得編輯的行選中
3、通過選中行數(shù)據(jù)selected結(jié)合datagrid 的getRowIndex方法獲取到編輯行索引index
4、通過index更新當(dāng)前行數(shù)據(jù)
實(shí)現(xiàn)中的問題
在執(zhí)行步驟4的時(shí)候發(fā)現(xiàn),如果是使用insertRow方式,會(huì)在頁(yè)面中停留一個(gè)下拉選面板異常

這里的原因就是。當(dāng)我們選中之后,執(zhí)行了更新行,再次之前沒有執(zhí)行編輯器editor的結(jié)束,導(dǎo)致此錯(cuò)誤;
解決方案有2種
先結(jié)束editor的編輯,然后在更新
dg.datagrid(‘endEdit’, rowIndex);
dg.datagrid(‘updateRow’,{
index:rowIndex,
row:row
});
直接刪除當(dāng)前行,然后在insertRow
dg.datagrid(‘deleteRow’,rowIndex); dg.datagrid(‘insertRow’,{
index:rowIndex,
row:row })
看大家實(shí)際需要,第一種方式,因?yàn)槲以?code>refreshRow種調(diào)用了td的點(diǎn)擊事件$td.click();,因此如果多行存在的話,每行都會(huì)被選中;所有都選中全選擇沒有打鉤

第二中方式則一行都不會(huì)被選中,我采用的是第二種方式,大家可以根據(jù)需要實(shí)際需要選擇。

第二個(gè)難點(diǎn)就是需要從當(dāng)前選中的下拉框獲取到編輯行,這里發(fā)現(xiàn)conbobox在datagrid中渲染的元素為
<td field="code">
<div style="width: 149px;" class="datagrid-cell datagrid-cell-c4-code datagrid-editable">
<table border="0" cellspacing="0" cellpadding="1">
<tbody>
<tr>
<td>
<input type="text" class="datagrid-editable-input combobox-f combo-f textbox-f" style="display: none;">
<span class="textbox combo" style="width: 147px; height: 20px;">
<span class="textbox-addon textbox-addon-right" style="right: 0px;">
<a href="javascript:void(0)" rel="external nofollow" class="textbox-icon combo-arrow" icon-index="0" style="width: 18px; height: 20px;"></a>
</span>
<input type="text" class="textbox-text validatebox-text" autocomplete="off" placeholder="" style="margin-left: 0px; margin-right: 18px; padding-top: 3px; padding-bottom: 3px; width: 121px;">
<input type="hidden" class="textbox-value" name="" value="9">
</span>
</td>
</tr>
</tbody>
</table>
</div>
</td>
因此這里獲取到td之后再執(zhí)行點(diǎn)擊事件
// 使用closest方法向上查找最近的td元素
let $table = $(this).closest('table');
// 獲取td
let $td = $table.closest('td');
$td.click();
const dg = $('#configTable');
const selected = dg.datagrid('getSelected');
// 獲取到當(dāng)前行
const rowIndex = dg.datagrid('getRowIndex',selected);以上希望能對(duì)大家有所幫助;如果大家有更好的辦法歡迎留言討論
到此這篇關(guān)于EasyUI彈出框行編輯,通過下拉框?qū)崿F(xiàn)內(nèi)容聯(lián)動(dòng)的文章就介紹到這了,更多相關(guān)EasyUI下拉框內(nèi)容聯(lián)動(dòng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
drag-and-drop實(shí)現(xiàn)圖片瀏覽器預(yù)覽
chrome的drag and drop API,它能將本地的圖片放到瀏覽器中進(jìn)行預(yù)覽,猜想一下當(dāng)我們把圖片拖拽到瀏覽器里會(huì)發(fā)生什么事情,你的瀏覽器試圖打開一個(gè)新的頁(yè)面并加載這個(gè)圖片。這篇文章給我們介紹drag-and-drop實(shí)現(xiàn)圖片瀏覽器預(yù)覽,需要的朋友可以參考下2015-08-08
js unicode 編碼解析關(guān)于數(shù)據(jù)轉(zhuǎn)換為中文的兩種方法
這篇文章主要介紹了js unicode 編碼解析關(guān)于數(shù)據(jù)轉(zhuǎn)換為中文的兩種方法,需要的朋友可以參考下2014-04-04
typescript中type和interface的區(qū)別有哪些
大家使用typescript總會(huì)使用到interface和type,所以下面這篇文章主要給大家介紹了關(guān)于typescript中type和interface區(qū)別的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-02-02
基于JS如何實(shí)現(xiàn)類似QQ好友頭像hover時(shí)顯示資料卡的效果(推薦)
通過本文給大家介紹鼠標(biāo)經(jīng)過好友列表中的好友頭像時(shí)顯示資料卡的效果,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-06-06
JS中const對(duì)于復(fù)雜類型變量和普通類型變量的區(qū)別詳解
我們?cè)陂_發(fā)的過程中一定常常發(fā)現(xiàn)const關(guān)鍵字定義的簡(jiǎn)單類型變量不可以改變,但是你如果定義的是一個(gè)復(fù)雜類型變量(比如對(duì)象)的話對(duì)里面屬性的增刪改查是可以的,那這又是為什么呢,接下來就來和小編一起探討一下吧2023-11-11
JavaScript中的對(duì)象的extensible屬性介紹
這篇文章主要介紹了JavaScript中的對(duì)象的extensible屬性介紹,JavaScript中,對(duì)象的extensible屬性用于表示是否允許在對(duì)象中動(dòng)態(tài)添加新的property,需要的朋友可以參考下2014-12-12
es6中Promise 對(duì)象基本功能與用法實(shí)例分析
這篇文章主要介紹了es6中Promise 對(duì)象基本功能與用法,結(jié)合實(shí)例形式分析了es6中Promise對(duì)象的基本功能、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-02-02

