New Metronic Docs!Added Integration Docs with Starter Kits Apps for Laravel, Laravel Livewire, Angular, Vue, Symfony, Blazor Server, Django & Flask & more
Browse Docs

Init KTSelect after call Ajax


Dear team,

I have a problem with KTSelect now when I initialize after calling Ajax and add select into drawer then dropdown of Select does not appear in correct position as shown in image.

How can I adjust it so that option of select shows in correct position

Best Regard,
Hoang Le


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi Hoàng Lê

This is a common issue with KTSelect in drawers and modals. Here are the recommended solutions:

The primary solution is to set the dropdownContainer option to 'body' when initializing KTSelect in drawers. Initialize KTSelect only after the drawer becomes visible.

// Wait for drawer to be shown
drawer.addEventListener("shown", function() {
// Initialize KTSelect here
const select = new KTSelect(element, {
dropdownContainer: "body"
});
});


Or using data attributes:

<select data-kt-select="{"dropdownContainer": "body"}">
<!-- options -->
</select>


If you're still experiencing positioning issues, ensure proper z-index handling:

const select = new KTSelect(element, {
dropdownContainer: "body",
zIndex: 9999 // Ensure dropdown appears above drawer
});



Dear Team,

Thanks for the solution and it works great but i have the same problem with dropdown how should i handle it?

Best Regard,
Hoàng Lê



Hi Hoàng Lê

The same solution that worked for KTSelect applies to other dropdown components. Set the dropdown container to 'body' for proper positioning:

// Wait for drawer to be shown
drawer.addEventListener("shown", function() {
// Initialize all dropdown components here
const dropdown = new KTDropdown(element, {
dropdownContainer: "body"
});
});


If you're still experiencing issues, try these additional configuration options:

const dropdown = new KTDropdown(element, {
dropdownContainer: "body",
dropdownStrategy: "fixed", // or "absolute"
dropdownZindex: 9999, // Ensure it appears above other elements
dropdownPlacement: "bottom-start" // Control positioning
});


Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(