Topic: Cannot Get Pro Components to Work

Kbateman0522 free asked 2 years ago

Expected behavior

Select Boxes and Datatables to render as shown in the examples: Select & Datatables

Actual behavior Datatables do not render at all and select renders as the default browser select box

Resources (screenshots, code snippets etc.) Select Box Screenshot

Datatable Screenshot (does not allow for sorting/etc)

Datatable Code: Laravel Blade Templates w/ MDBootstrap

            <div class="datatable">
        <table class="table">
            <thead class="table-light">
                <th scope="col" colspan="4">Topic</th>
                <th scope="col" colspan="2">Users</th>
                <th scope="col" colspan="2">Last Reply</th>
            @foreach($conversations as $conversation)
                $conversationMessages = $conversation->participants()->where('user_id',Auth::user()->id)->where('read_latest', 0)->latest('conversation_id')->first();
                    <tr style="background-color: rgba(242,233,247,0.77);">
                    <td colspan="4"><a href="{{url('/message/'.$conversation->id)}}"><h4>{{$conversation->topic}}</h4></a></td>
                    <td colspan="2">@foreach($conversation->participants as $participant)
                                {!! $participant->profileLink() !!}
                                {!! $participant->profileLink() !!},
                    <td colspan="2">{{ $conversation->updated_at->diffForHumans() }}</td>

Select Code: Laravel Blade Template w/ MDBootstrap

         <div class="input-group mb-3">
         <span class="input-group-text">Forum Avatar</span>
       <select name="avatar" class="select" data-mdb-filter="true">
         @foreach($avatars as $av)
           <option value="{{$av['value']}}"
                   @if ($av['value'] == old('avatar', $user->avatar))
         <option disabled>--------------------</option>
         @foreach($user->pets as $pet)
           <option value="pet_{{$pet->id}}"
                   @if ("pet_".$pet->id == old('avatar', $user->avatar))
       @foreach ($errors->get('avatar') as $message)

Header/Footer JS & CSS Code

   <!-- Font Awesome -->
<script src="" crossorigin="anonymous"></script>
<!-- Google Fonts Roboto -->
<link rel="stylesheet" href=",400,500,700&display=swap">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="/css/mdb.css">
<link href="/css/new.css" rel="stylesheet" type="text/css">

anlix free answered 2 years ago

The same is happening to me. I'm already importing a single module like this:

import { Select } from 'mdb-ui-kit';

But the default browser select is rendered.

I started my project using Create React App. I have no server rendering implemented. My component looks like this:

function MySelect (props) {
  const selectRef = useRef(null);

  useEffect(() => {
    const sel = Select.getInstance(selectRef.current);
    console.log('select instance', sel);
    if (sel && sel.setValue !== undefined) sel.setValue('3'); // IF to avoid errors.
  }, [])

  return <select ref={selectRef} className="select" {...props}>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    <option value="4">Four</option>
    <option value="5">Five</option>

The line console.log('select instance', sel) outputs:

select instance null

Using document.querySelector('element') instead of using React Ref, has the same result.

The default browser select is rendered and mdb doesn't return an instance when calling Select.getInstance(...).

Grzegorz Bujański staff commented 2 years ago

Do you use MDB5 Standard or MDB5 React?

Grzegorz Bujański staff answered 2 years ago

I guess it could be the order in which the code is executed. Probably the MDB is loaded first, and then the HTML code is rendered.

try to manually initialize Datatables and Select. Here you will find information on how to do it:

Kbateman0522 free answered 2 years ago

It seems it cut off my footer JS code, so here it is in a snippet:

Snippet w/ JS Files

Please insert min. 20 characters.


Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.



Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 3.8.0
  • Device: Macbook Pro
  • Browser: Chrome & Firefox
  • OS: macOS Big Sur
  • Provided sample code: No
  • Provided link: Yes