Loading ...
Sorry, an error occurred while loading the content.

Re: Mysql / Datatable / Html Markup - How to have Genric functions

Expand Messages
  • dominiquemege
    Thanks for your complete answer ... Dominique.
    Message 1 of 3 , Nov 28, 2007
    • 0 Attachment
      Thanks for your complete answer
      :)

      Dominique.

      --- In ydn-javascript@yahoogroups.com, "Satyam" <satyam@...> wrote:
      >
      > There was a similar question some weeks ago. I'll try to sumarize it.
      >
      > The best would be to use the connection manager directly and call the PHP
      > server to retrieve both the meta information and the data itself in one
      > single package, either in JSON or XML format. Either of those two formats
      > can represent structured information, which a plain text table cannot and,
      > since it is not going to be displayed, using HTML would not make sense.
      > Besides, you would need to provide some more information, not just the field
      > names (as you could in TH elements in an HTML table) but also the data types
      > so the client DataTable knows how to format it, or labels or whatever else
      > you might need.
      >
      > Once you read the server reply, you would use the meta-information to build
      > both the column definitions and the fields array for the DataSource. Then,
      > you would create a DataSource instance with a reference to the data, which
      > will be either a JavaScript array if you used JSON or a DOM node if you used
      > XML.
      >
      > Creating the DataTable from a 'local' source (since the DataSource itself
      > was not involved in fetching the data, for all it knows, it is local) makes
      > all the communication rely on a single request both for the data and
      > meta-data, saving yourself from the latency of two separate requests. If
      > done separately, those two requests cannot run concurrently because you
      > would need the meta-data before launching the second one for the data.
      > Nevertheless, if you were to use server-side pagination or sorting, you
      > might still want to do two separate requests because you would have the
      > meta-data just once and the data as required. The options open up. You can
      > send a flag requesting the meta-data the first time around and skip it in
      > later requests, which would then carry only data. You can also make two
      > separate requests via the connection manager. Since the DataSource expects
      > to know the name of the fields to parse, it would require you to do the two
      > queries in sequence. If you use the connection manager directly, you can
      > launch both requests at once and once both meta-data and data arrived, you
      > can create the DataSource reading from local data. I'm not really sure how
      > 'simultaneous' both calls can be, I'm not really well versed in the XHR
      > object so perhaps there can be only one outstanding communication at once
      > so, just in case, I would prefere to pack both data and, optionally,
      > meta-data in the same message.
      >
      > Satyam
      >
      >
      >
      >
      >
      > ----- Original Message -----
      > From: "dominiquemege" <dominiquemege@...>
      > To: <ydn-javascript@yahoogroups.com>
      > Sent: Tuesday, November 27, 2007 10:43 AM
      > Subject: [ydn-javascript] Mysql / Datatable / Html Markup - How to have
      > Genric functions
      >
      >
      > > Hello all,
      > >
      > > I'm working on a generic way to display HTML tables (done with PHP and
      > > Mysql).
      > > I know how to have a datatable with YUI when I know how many columns I
      > > have in my
      > > request and there name.
      > >
      > > I have something like this :
      > > echo "<table id='accounts'>";
      > > echo "<thead>";
      > > echo "<tr>";
      > > $i = 0;
      > > while ($i < $Nfield)
      > > {
      > > $meta = mysql_fetch_field($result, $i);
      > > echo "<th>$meta->name</th>";
      > > $i++;
      > > }
      > > echo "</tr>";
      > > echo "</thead>";
      > >
      > > while ($row=mysql_fetch_row($result))
      > > {
      > > echo "<tr>";
      > > foreach($row as $value)
      > > {
      > > echo "<td>$value</td>";
      > > }
      > > echo "</tr>";
      > > }
      > >
      > > echo "</table>";
      > >
      > > mysql_close($connect);
      > >
      > > ?>
      > > </div>
      > >
      > >
      > >
      > > <script type="text/javascript">
      > > YAHOO.util.Event.addListener(window, "load", function() {
      > > YAHOO.example.EnhanceFromMarkup = new function() {
      > > var myColumnDefs = [
      > > {key:"id",label:"Id",sortable:true},
      > > {key:"appellation",label:"appellation", sortable:true},
      > > {key:"pays",label:"pays",sortable:true},
      > > {key:"region",label:"Region",sortable:true},
      > > {key:"Owner",label:"Owner",sortable:true}
      > > ];
      > >
      > > this.myDataSource = new
      > > YAHOO.util.DataSource(YAHOO.util.Dom.get("accounts"));
      > > this.myDataSource.responseType =
      > > YAHOO.util.DataSource.TYPE_HTMLTABLE;
      > > this.myDataSource.responseSchema = {
      > > fields: [{key:"id"},
      > > {key:"appellation"},
      > > {key:"pays"},
      > > {key:"region"},
      > > {key:"Owner"}
      > > ]
      > > };
      > >
      > > this.myDataTable = new YAHOO.widget.DataTable("markup",
      > > myColumnDefs,
      > > this.myDataSource,
      > > {sortedBy:{key:"id",dir:"desc"}});
      > > };
      > >
      > > this.parseNumberFromCurrency = function(sString) {
      > > // Remove dollar sign and make it a float
      > > return parseFloat(sString.substring(1));
      > > };
      > > });
      > > </script>
      > >
      > > BUT : I want to know if it is possible to define myColumnsDefs with the
      > > name of Mysql
      > > Database in a programming way (without knowing them when coding) ?
      > >
      > > I'm not sure I'm clear ?
      > >
      > > Thanks for your help.
      > >
      > > Dominique.
      > >
      > >
      > >
      > >
      > > Yahoo! Groups Links
      > >
      > >
      > >
      > >
      > >
      > > --
      > > No virus found in this incoming message.
      > > Checked by AVG Free Edition.
      > > Version: 7.5.503 / Virus Database: 269.16.8/1153 - Release Date:
      > > 26/11/2007 21:08
      > >
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.