翻譯|行業(yè)資訊|編輯:張蓉|2025-05-30 13:37:12.763|閱讀 125 次
概述:數(shù)據(jù)編輯是 DHTMLX Grid 組件所具備的眾多強(qiáng)大功能之一。將其與 Grid 的其他優(yōu)勢(如高度可定制性以及與 Suite 組件的互操作性)相結(jié)合,您可以添加自定義編輯選項來滿足特定用例場景的需求。在本文中,您將了解如何通過數(shù)據(jù)視圖編輯器來豐富 Grid 的配置。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
數(shù)據(jù)編輯是 DHTMLX Grid 組件所具備的眾多強(qiáng)大功能之一。將其與 Grid 的其他優(yōu)勢(如高度可定制性以及與 Suite 組件的互操作性)相結(jié)合,您可以添加自定義編輯選項來滿足特定用例場景的需求。在本文中,您將了解如何通過數(shù)據(jù)視圖編輯器來豐富 Grid 的配置。
const grid = new dhx.Grid("grid", { columns: [ { id: "project", header: [{ text: "Project" }], width: 180 }, { id: "owner", header: [{ text: "Owner" }], mark: () => "dataview-editor", editable: false, autoWidth: true }, … // Config for other columns ], selection: true, editable: true, keyNavigation: false, data, });在這一步中,您還需要定義網(wǎng)格的默認(rèn)行為 —— 啟用編輯、選擇功能,禁用鍵盤導(dǎo)航,并加載初始數(shù)據(jù)。
const dataview = new dhx.DataView(null, { selection: true, itemsInRow: 2, template: ({ name, photo, post, phone, birthday, mail }) => (` ... // Custom HTML layout for cards appearing in the editor `), `), data: owner_data, });
const popup = new dhx.Popup({ css: "dhx_widget--border-shadow popup", }); popup.attach(dataview);
eventHandlers: { onclick: { "dataview-editor": (event, { row, col }) => { const ownrer = dataview.data.find(item => item.name == row[col.id]); dataview.selection.add(ownrer.id);// Highlights the selected card in the DataView popup.show(event.target, { centering: false });// Opens the popup near the clicked element } } },
dataview.events.on("AfterSelect", () => { const owner = dataview.selection.getItem(); const { row } = grid.selection.getCell(); grid.data.update(row.id, { "owner": owner.name }); popup.hide(); });這一步使自定義編輯器按預(yù)期運(yùn)行 —— 用戶點(diǎn)擊單元格、選擇卡片,網(wǎng)格會實(shí)時更新內(nèi)容。
… .dhx_dataview_template_d__picture { width: 110px; min-width: 110px; background: center center/cover no-repeat #f7f7f7; } .dhx_dataview_template_d__picture:before { content: ""; display: block; padding-top: 100%; } .dhx_dataview_template_d__body { padding-left: 12px; width: 150px; } …這些樣式用于在初始化dhx.DataView時,對步驟 2 中提供的 DataView 項模板進(jìn)行結(jié)構(gòu)和樣式設(shè)置。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn