scala.js - How to invoke 3rd party javascript from scala-js? -


i need initializing native js var within scalajs app (specifically scalajs-react app). fundamentally, i'm trying use bootstrap responsive data-tables , need initialize data table getting element of data table in html via call dom.getelementbyid of type datatable , need initialize this:

$(document).ready(function() {     $('#example').datatable(); } ); 

i've been staring @ @js.native stuff , can't quite figure out how make connection native js. appreciated. reference, link native javascript of responsive data-table here. additional question scalajs-react background (are there @japgolly?) whether or not best place make data-table initialization invocation should in reactcomponentb.componentdidmount() method?

the simplest way set data table doing using dynamic api:

dom.document.getelementbyid("example").asinstanceof[js.dynamic].datatable() 

of course need once document loaded. can use scala-js-jquery so:

jquery(dom.document).ready(() =>   dom.document.getelementbyid("example").asinstanceof[js.dynamic].datatable() ) 

if have nicer (and typesafe) invocation of datatable, can follow monkey patching guide (sorry no anchor, search term):

@js.native trait datatableelement extends dom.element {   def datatable(): unit = js.native }  object datatableelement {   implicit def element2datatableelement(e: dom.element): datatableelement =   {     e.asinstanceof[datatableelement]   } } 

you won't need cast anymore:

dom.document.getelementbyid("example").datatable() 

and:

jquery(dom.document).ready(() =>   dom.document.getelementbyid("example").datatable() ) 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -