Is there any way to show child tables data in Frappe Data-Table using dialog popup?
You can display a table in frappe.dialog.
@TurkerTunali, thank you for your response. I know I can show child table in a frappe.dialog. Is it possible to show Data Table in frappe.dialog?
Sure. Table in a dialog example
const frm = opts.frm;
const warehouse_field = opts.warehouse_field || 'warehouse';
const item_field = opts.item_field || 'item_code';
this.data = [];
const dialog = new frappe.ui.Dialog({
title: __("Select Alternate Item"),
fields: [
{fieldtype:'Section Break', label: __('Items')},
{
fieldname: "alternative_items",
fieldtype: "Table",
cannot_add_rows: true,
in_place_edit: true,
data: this.data,
get_data: () => {
return this.data;
},
fields: [{
fieldtype:'Data',
fieldname:"docname",
hidden: 1
}, {
fieldtype:'Link',
fieldname:"item_code",
options: 'Item',
in_list_view: 1,
read_only: 1,
label: __('Item Code')
}, {
fieldtype:'Link',
fieldname:"alternate_item",
options: 'Item',
default: "",
in_list_view: 1,
label: __('Alternate Item'),
onchange: function() {
const item_code = this.get_value();
const warehouse = this.grid_row.on_grid_fields_dict.warehouse.get_value();
if (item_code && warehouse) {
frappe.call({
method: "erpnext.stock.utils.get_latest_stock_qty",
args: {
item_code: item_code,
warehouse: warehouse
},
callback: (r) => {
this.grid_row.on_grid_fields_dict
.actual_qty.set_value(r.message || 0);
}
})
}
},
get_query: (e) => {
return {
query: "erpnext.stock.doctype.item_alternative.item_alternative.get_alternative_items",
filters: {
item_code: e.item_code
}
};
}
}, {
fieldtype:'Link',
fieldname:"warehouse",
options: 'Warehouse',
default: "",
in_list_view: 1,
label: __('Warehouse'),
onchange: function() {
const warehouse = this.get_value();
const item_code = this.grid_row.on_grid_fields_dict.item_code.get_value();
if (item_code && warehouse) {
frappe.call({
method: "erpnext.stock.utils.get_latest_stock_qty",
args: {
item_code: item_code,
warehouse: warehouse
},
callback: (r) => {
this.grid_row.on_grid_fields_dict
.actual_qty.set_value(r.message || 0);
}
})
}
},
}, {
fieldtype:'Float',
fieldname:"actual_qty",
default: 0,
read_only: 1,
in_list_view: 1,
label: __('Available Qty')
}]
},
],
primary_action: function() {
const args = this.get_values()["alternative_items"];
const alternative_items = args.filter(d => {
if (d.alternate_item && d.item_code != d.alternate_item) {
return true;
}
});
alternative_items.forEach(d => {
let row = frappe.get_doc(opts.child_doctype, d.docname);
let qty = null;
if (row.doctype === 'Work Order Item') {
qty = row.required_qty;
} else {
qty = row.qty;
}
row[item_field] = d.alternate_item;
frm.script_manager.trigger(item_field, row.doctype, row.name)
.then(() => {
frappe.model.set_value(row.doctype, row.name, 'qty', qty);
frappe.model.set_value(row.doctype, row.name,
opts.original_item_field, d.item_code);
});
});
refresh_field(opts.child_docname);
this.hide();
},
primary_action_label: __('Update')
});
frm.doc[opts.child_docname].forEach(d => {
if (!opts.condition || opts.condition(d)) {
dialog.fields_dict.alternative_items.df.data.push({
"docname": d.name,
"item_code": d[item_field],
"warehouse": d[warehouse_field],
"actual_qty": d.actual_qty
});
}
})
this.data = dialog.fields_dict.alternative_items.df.data;
dialog.fields_dict.alternative_items.grid.refresh();
dialog.show();
1 Like
I was scratching my head since morning on the above lines of code
this.get_value() does not work with ‘onchange’, we should use ‘change’ instead of ‘onchange’ now.
Is it ok?
below is working fine for me.
change: function() {
const item_code = this.get_value();