Datatable in custom html block

Hi everyone,

I am trying to use frappe datatable inside a custom html block:

html code

<!DOCTYPE html>
<div class="datatable"></div>

javascript code

let elt = root_element.querySelector(".datatable");

   let datatable = new frappe.DataTable(elt, {
	columns: ['A', 'B', 'C'],
	data: [
		['1', '2', '3']
	]
});

That is what I get

Would have someone any idea ?

hello getting any solution on above datatable in custom html block

Hi Kaushalk,

unfortunately not.
However I did not test it recently.

Bets regards,

Gerald

What problem are you facing?

The same as @gmeunier or something else?

Try This Code

const datatable_element = root_element.find(".datatable")[0];

   const datatable = new frappe.DataTable(datatable_element, {
	columns: ['A', 'B', 'C'],
	data: [
		['1', '2', '3']
	]
});

same issue facing


i add that code in js but still data table not showing

console variables once and share that

Sorry, Instead of this use querySelector.

used querySelector but still table not showing

Hello all,
good to know about frappe.DataTable element, I do not know about it yet…

I have tried these steps:

  • create html field, “option” = <div class="pojd"></div>
  • in browser console: let custom_table = $('div.pojd').get(0);
  • in browser console:
let datatable = new frappe.DataTable(custom_table, {
    columns: ['A', 'B', 'C'],
    data: [
        ['1', '2', '3']
    ]
});

And here is result :wink:

Thank you
Jiri Sir

1 Like


try same code but in custom html block data table not show

What is your requirement?

You can use Custom Page if your requirements meet.

Hello,
it is not obviously working in custom block :frowning:
The element is not found in DOM and root_element.querySelector made the same messy table as mentioned in this topic.
I will take some time and go through it.

Jiri Sir

Hi Everyone,

In fact in my first post, the datatable is working:
You do see the headers, the lines and some formatting appearing.

It is just that the datatable is completely messed up.
Headers and rows are vertical, rows on the left, headers on the right.
And there is a text input field at the bottom

For me it looks more like there is a css conflict linked to css or DOM.

Gerald