jquery - Javascript blocking rest of script -


i'm using datatables , wanted add colreorder extension. extension worked fine broke lot of ajax calls have in js file , can't figure out why.

the code brakes js

var colreorder = new $.fn.datatable.colreorder( testtable, {     "aiorder": [ 0, 1, 2, 3, 4, 5 ] });  $('.reset-order-btn').click( function () {     colreorder.fnreset();     toastr["info"]("columns reordered");     return false; } ); 

why happen?

edit: managed narrow down further

this brakes js:

var colreorder = new $.fn.datatable.colreorder( testtable, {     "aiorder": [ 0, 1, 2, 3, 4, 5 ] }); 

edit 2 clarification

so far i've found these 2 functions doesn't work more. won't start when click on buttons. there might other things not working haven't tested of them yet.

$('#delete-all-selections').click(function(){     $.ajax({             type:"get",             url:"/testdata/selection-delete-all/",             contenttype: "application/json; charset=utf-8",             success: function (data) {                     var mynode = document.getelementbyid("selections-list");                     mynode.innerhtml = '';                     toastr["error"]("all selections deleted");                     getselection();             }     }) });  $('.selection-delete-btn').click(function(){     var selectid = this.getattribute('data');     console.log(selectid);     $.ajax({             type:"get",             url:"/testdata/selection-delete/"+selectid,             contenttype: "application/json; charset=utf-8",             success: function (data) {                     json = $.parsejson(data)                     var mynode = document.getelementbyid("selections-list");                     mynode = mynode.children[json.selectid]                     console.log(mynode)                     $(mynode).remove()                     toastr["error"]("selection deleted");                     getselection();             }     }) }); 

and if remove var colreorder lines works intended again.

edit 3: found error in js console

uncaught typeerror: cannot read property '_colreorder' of undefined  

i've found tries run function when load page has buttons stop working , why crashes. think need split js file , load them individually on each page.

after lot of trying different stuff managed solve problem out. i'm not exaclty sure how works did.

i added initcomplete part of table options:

colreorder = new $.fn.datatable.colreorder( testtable, {     "aiorder": [ 0, 1, 2, 3, 4, 5 ] }); 

without var colreorder become global variable. use without blocking other functions:

$('.reset-order-btn').click( function () {     colreorder.fnreset();     toastr["info"]("columns reordered");     return false; } ); 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -