0

I'm trying to load a .htm template from .js file. But there is a script present in .htm file which gets triggers when the template is loaded and things are smooth.

Here how the template looks. testing.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>http://stackoverflow.com/questions/6946559/jqgrid-please-help</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <script type="text/javascript" charset="utf-8">
            $(document).ready(function () {
                $('#example').dataTable({
                    "bProcessing": true,
                    "sAjaxSource": '/Home/GetData',
                    "sScrollY": "400px",
                    "sScrollX": "200px",
                    "bPaginate": false
                });
            });
        </script>

 </head>
<div id="dynamic">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
    <thead>
        <tr>
            <th width="20%">Date</th>
            <th width="25%">Name</th>
            <th width="25%">ProposalID</th>
            <th width="25%">Time</th>
               </tr>
    </thead>
    <tbody>
   </tbody>

</table>
</div>
</html>

Here is the .js file which loads the template.

var iTabs = function () {
    return {
        Init: function () {

            var placeholder = $("#testtab");
            placeholder.setTemplateURL("/Templates/Home/testing.htm");

            placeholder.load("/Templates/Home/testing.htm");


        }
    }
} ();

But, now i want to execute the .htm script in .js file i.e after loading the template. If i run only a part of script i.e

$('#example').dataTable({
                        "bProcessing": true,
                        "sAjaxSource": '/Home/GetData',
                        "sScrollY": "400px",
                        "sScrollX": "200px",
                        "bPaginate": false
                    });

in .js file, it wont work. Is it possible to run this script in .js file?. if so how?

Naruto
  • 9,476
  • 37
  • 118
  • 201

1 Answers1

1

Try to run that js code using the callback of the load

Like this :

placeholder.load("/Templates/Home/rpt.htm", function() {
  $('#example').dataTable({
                    "bProcessing": true,
                    "sAjaxSource": '/Home/GetData',
                    "sScrollY": "400px",
                    "sScrollX": "200px",
                    "bPaginate": false
                });
});

For more info , refer to the jQuery load docs

Daniel
  • 36,833
  • 10
  • 119
  • 200
  • It throws me error Whoops! The page you're looking does not exist. :( – Naruto Jan 17 '13 at 10:57
  • Cant we load this separately like first loading the grid and then rendering the data? – Naruto Jan 17 '13 at 10:58
  • The page you're looking does not exist = wrong path provided... try to play with it , for example `Templates/Home/rpt.htm` or `./Templates/Home/rpt.htm` etc – Daniel Jan 17 '13 at 11:00
  • Ya i will check it, one thing i m wondering. this will trigger on load document. what if i need to show data on a button click? in tat case how to do? – Naruto Jan 17 '13 at 11:04