Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Select2 - trying to implement from url - https://jsfiddle.net/the94air/awzqtd4w/ but data is not loading

(0) ShareShare
ReportReport
Posted on by 130

<html lang="en">
<head>
    <title>Jquery Select2 - Select Box with Search Option</title> 
    <script src="ajax.googleapis.com/.../jquery.js"></script>

 <link href="cdnjs.cloudflare.com/.../select2.min.css" rel="stylesheet" />

 <script src="cdnjs.cloudflare.com/.../select2.min.js"></script>
</head>

<script type="text/javascript">

var data = [{
   id: 0,
   text: 'enhancement',
 html: '<div style="color:green">enhancement</div>'
}, {
   id: 1,
   text: 'bug',
 html: '<div style="color:red">bug</div><div><small>This is some small text on a new line</small></div>'
}];

function template(data) {
 return data.html;
}

$("select").select2({
   data: data,
   templateResult: template,
   escapeMarkup: function(m) {
      return m;
   }
})

</script>


<body>


  <select class="myselect" style="width:500px;">


  </select>


</div>


<script type="text/javascript">

      $(".myselect").select2();

</script>


</body>


</html>

*This post is locked for comments

  • VinodTakke Profile Picture
    VinodTakke 130 on at
    RE: Select2 - trying to implement from url - https://jsfiddle.net/the94air/awzqtd4w/ but data is not loading

    // This worked I was calling $(".myselect").select2() twice so I removed 1 and it worked.

    <html lang="en">

    <head>

       <title>Jquery Select2 - Select Box with Search Option</title>  

       <script src="ajax.googleapis.com/.../jquery.js&quot;></script>

    <link href="cdnjs.cloudflare.com/.../select2.min.css&quot; rel="stylesheet" />

    <script src="cdnjs.cloudflare.com/.../select2.min.js&quot;></script>

    </head>

    <script type="text/javascript">

    var data = [{

      id: 0,

      text: 'enhancement',

    html: '<div style="color:green">enhancement</div>'

    }, {

      id: 1,

      text: 'bug',

    html: '<div style="color:red">bug</div><div><small>This is some small text on a new line</small></div>'

    }];

    function template(data) {

    return data.html;

    }

    </script>

    <body>

     <select class="myselect" style="width:500px;">

     </select>

    </div>

    <script type="text/javascript">

     $(".myselect").select2({

      data: data,

      templateResult: template,

      escapeMarkup: function(m) {

         return m;

      }

    });

    </script>

    </body>

    </html>

  • VinodTakke Profile Picture
    VinodTakke 130 on at
    RE: Select2 - trying to implement from url - https://jsfiddle.net/the94air/awzqtd4w/ but data is not loading

    Thanks for the reply Andrew I debugged by F12 data gets loaded in data object but it get vanish when it call method template()

  • Verified answer
    a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: Select2 - trying to implement from url - https://jsfiddle.net/the94air/awzqtd4w/ but data is not loading

    Hello,

    I would suggest to open Browser Tools and check what's going wrong - blogs.msdn.microsoft.com/.../debugging-custom-javascript-code-in-crm-using-browser-developer-tools

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,309 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans