Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add on_add_row event for grid in Dialog #26535

Merged
merged 2 commits into from
May 27, 2024
Merged

Conversation

marination
Copy link
Collaborator

@marination marination commented May 22, 2024

Documentation: https://frappeframework.com/docs/user/en/api/dialog?editWiki=1&wikiPagePatch=aj13edb2n0

  • Add an event on_add_row to a grid that is not inside a form (eg. in a dialog)
  • This can be used to manipulate data and add presets to the dialog grid dynamically

Usage:

const dialog = new frappe.ui.Dialog({
	title: __("Create Logs"),
	fields: [
		{
			fieldname: "logs",
			fieldtype: "Table",
			label: __("Logs"),
			in_place_edit: true,
			reqd: 1,
			fields: table_fields,
			// set data on row addition, idx = visible idx of the row
			// set `log_type` as alternating IN/OUT in dialog table on row addition
			on_add_row: (idx) => {
				let data_id = idx - 1;
				let logs = dialog.fields_dict.logs;
				let log_type = (data_id % 2) == 0 ? "IN" : "OUT";

				logs.df.data[data_id].log_type = log_type;
				logs.grid.refresh();
			},
		},
	],
	primary_action: (values) => {},
	primary_action_label: __("Create"),
});

- This can be used to manipulate data and add presets to the grid dynamically
@marination marination marked this pull request as ready for review May 22, 2024 13:44
frappe/public/js/frappe/form/grid.js Outdated Show resolved Hide resolved
@marination marination merged commit 135713a into develop May 27, 2024
24 checks passed
@marination marination deleted the dialog-grid-add-row branch May 27, 2024 15:08
@marination marination added the backport version-14-hotfix backport to version 14 label May 27, 2024
marination added a commit that referenced this pull request May 27, 2024
…-26535

feat: Add `on_add_row` event for grid in Dialog (backport #26535)
marination added a commit that referenced this pull request May 27, 2024
…-26535

feat: Add `on_add_row` event for grid in Dialog (backport #26535)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14 backport version-15-hotfix Backport the PR to v15
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants