web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

  • VinodTakke Profile Picture
    130 on at

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

  • VinodTakke Profile Picture
    130 on at

    // 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>

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans