asp.net mvc - TypeError $(...) is not a function when using a jquery plugin -


i got 1 jquery experts.

i downloaded simple jquery plugin convert table csv.

here source code... http://www.kunalbabre.com/projects/table2csv.js

now, created local jscript file. jquery.table2csv.js. added page right after jquery

<script type="text/javascript" src='@url.content("~/scripts/libs/jquery-1.6.3.min.js")'></script> <script type="text/javascript" src='@url.content("~/scripts/jquery.table2csv.js")'></script> 

it's loading correct (200 ok) according firebug.

in 1 of views, have following code...

<script>     $(document).ready(function () {         $("#exporttocsv").click(function (event) {              event.preventdefault();             alert('button clicked!');             $('#reportdatatable').table2csv();         });     }); </script> 

the trigger fires click event, no problem, following error.

typeerror: $(...).table2csv not function

(?)(event=object { originalevent=event click, type="click", timestamp=88685109, more...})summary (line 109) add(c=object { originalevent=event click, type="click", timestamp=88685109, more...})asset....zogaqaa (line 3) add(a=click clientx=849, clienty=231)asset....zogaqaa (line 3) [break on error]

$('#reportdatatable').table2csv();

i tried find meaningful here no solution far.

can me understand what's going on here?

thanks.

edit:

here source code plugin.

jquery.fn.table2csv = function(options) {     var options = jquery.extend({         separator: ',',         header: [],         delivery: 'popup' // popup, value     },     options);      var csvdata = [];     var headerarr = [];     var el = this;      //header     var numcols = options.header.length;     var tmprow = []; // construct header avalible array      if (numcols > 0) {         (var = 0; < numcols; i++) {             tmprow[tmprow.length] = formatdata(options.header[i]);         }     } else {         $(el).filter(':visible').find('th').each(function() {             if ($(this).css('display') != 'none') tmprow[tmprow.length] = formatdata($(this).html());         });     }      row2csv(tmprow);      // actual data     $(el).find('tr').each(function() {         var tmprow = [];         $(this).filter(':visible').find('td').each(function() {             if ($(this).css('display') != 'none') tmprow[tmprow.length] = formatdata($(this).html());         });         row2csv(tmprow);     });     if (options.delivery == 'popup') {         var mydata = csvdata.join('\n');         return popup(mydata);     } else {         var mydata = csvdata.join('\n');         return mydata;     }      function row2csv(tmprow) {         var tmp = tmprow.join('') // remove blank rows         // alert(tmp);         if (tmprow.length > 0 && tmp != '') {             var mystr = tmprow.join(options.separator);             csvdata[csvdata.length] = mystr;         }     }     function formatdata(input) {         // replace " “         var regexp = new regexp(/["]/g);         var output = input.replace(regexp, "“");         //html         var regexp = new regexp(/\<[^\<]+\>/g);         var output = output.replace(regexp, "");         if (output == "") return '';         return '"' + output + '"';     }     function popup(data) {         var generator = window.open('', 'csv', 'height=400,width=600');         generator.document.write('<html><head><title>csv</title>');         generator.document.write('</head><body >');         generator.document.write('<textarea cols=70 rows=15 wrap="off" >');         generator.document.write(data);         generator.document.write('</textarea>');         generator.document.write('</body></html>');         generator.document.close();         return true;     } }; 

ok. new edit @ end of scripts, had mr. telerik...

@(html.telerik().scriptregistrar().defaultgroup(group => group.combined(true).compress(true))) 

i removed , worked fine. 1 little problem thou. jqueries telerik don't work.... doing research in meantime on how make guy coexist jqueries.

solved.... here solution.

http://www.telerik.com/community/forums/aspnet-mvc/general/telerik-doesn-t-let-me-work-with-jquery-ui.aspx

i hope helps people in future.

basically, seems telerik registration of own jquery files adds jquery (double registration).

thank you


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -