Merge pull request #35398 from aerele/feat/data-exporter-search

feat(data_exporter): add search support and improve option visibility
This commit is contained in:
Ejaaz Khan 2026-01-11 23:44:06 +05:30 committed by GitHub
commit 299c1c1c0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 69 additions and 16 deletions

View file

@ -91,12 +91,13 @@ frappe.data_import.DataExporter = class DataExporter {
],
primary_action_label: __("Export"),
primary_action: (values) => this.export_records(values),
on_page_show: () => this.select_mandatory(),
on_page_show: () => this.setup_on_page_show(),
});
this.make_filter_area();
this.make_select_all_buttons();
this.update_record_count_message();
this.setup_search_input();
this.dialog.show();
}
@ -303,6 +304,29 @@ frappe.data_import.DataExporter = class DataExporter {
};
});
}
setup_search_input() {
const $wrapper = this.dialog.get_field("select_all_buttons").$wrapper;
// prevent duplicate search inputs
if (this.dialog.$wrapper.find(".filters-search").length) return;
$wrapper.before(`
<div class="filters-search">
<input
type="text"
placeholder="${__("Search")}"
data-element="search"
class="form-control input-xs"
>
</div>
`);
}
setup_on_page_show() {
frappe.utils.setup_search(this.dialog.$body, ".unit-checkbox", ".label-area");
this.select_mandatory();
}
};
export function get_columns_for_picker(doctype) {

View file

@ -979,25 +979,54 @@ Object.assign(frappe.utils, {
const $search_input = $wrapper.find('[data-element="search"]').show();
$search_input.focus().val("");
const $elements = $wrapper.find(el_class).show();
const $multichecks = $wrapper.find('[data-fieldtype="MultiCheck"]');
let $no_results = $wrapper.find(".no-results-message");
if (!$no_results.length) {
$no_results = $(`
<div class="no-results-message text-muted text-center" style="padding: 5px; display: none;">
${__("No values to show")}
</div>
`).appendTo($wrapper);
}
$no_results.hide();
const matches_filter = ($el, filter) => {
const $text_el = $el.find(text_class);
const text = $text_el.text().toLowerCase();
let name = "";
if (data_attr && $text_el.attr(data_attr)) {
name = $text_el.attr(data_attr).toLowerCase();
}
return text.includes(filter) || name.includes(filter);
};
$search_input.off("keyup").on("keyup", () => {
let text_filter = $search_input.val().toLowerCase();
// Replace trailing and leading spaces
text_filter = text_filter.replace(/^\s+|\s+$/g, "");
for (let i = 0; i < $elements.length; i++) {
const text_element = $elements.eq(i).find(text_class);
const text = text_element.text().toLowerCase();
const text_filter = $search_input.val().toLowerCase().trim();
let any_visible = false;
let name = "";
if (data_attr && text_element.attr(data_attr)) {
name = text_element.attr(data_attr).toLowerCase();
}
$elements.each(function () {
const match = matches_filter($(this), text_filter);
$(this).toggle(match);
if (match) any_visible = true;
});
if (text.includes(text_filter) || name.includes(text_filter)) {
$elements.eq(i).css("display", "");
} else {
$elements.eq(i).css("display", "none");
}
if ($multichecks.length) {
$multichecks.show();
$multichecks.each(function () {
const has_visible = $(this).find(el_class + ":visible").length;
$(this).toggle(!!has_visible);
});
}
if (text_filter) {
$no_results.toggle(!any_visible);
} else {
$no_results.hide();
}
});
},