I've been coding a lot of "data table" stuff recently and i have been
following the pattern of what the plugin "inGrid" does:

which is have an empty table like:

<table id="Replace_Table">
    <thead>
         <tr>
               <th>Data Column</th>
               <th>Use in Email Body</th>
               <th>Test Value</th>
         </tr>
    </thead>
    <tbody></tbody>
</table>


And using the $.getJSON method, i call my server side script (in my
case, ASP.NET, but that's irrelevant) and return a user defined class
converted to JSON

this object has 3 properties
- (.HasError) First is a boolean whether the call was successful or
not (after running business rules, etc)
- (.Message) Second is a string message if needed
- (.Data) A generic "object" that could be whatever one desires, in
the case of the data table stuff, it'll be the html of the <tr>'s and
a pager row if needed

So the code to call it would be like

$.getJSON(
     "SomeHandler.ashx",
     { Mode: "TableData" },
     function(json) {
          if (json.HasError) {
               alert(json.Message);
          }
          else {
               $("#Replace_Table > tbody").html(json.Data);
          }
     }
);



Not saying this is the best overall way, but it surely has been
working fine for me, and it keeps my JavaScript free of html  :-)

Reply via email to