0

I'm happy to say that I've succeeded in importing an Access database into MySQL and getting a table from it to show up in Views. Progress! Thank you for all the help I’ve been getting here to overcome the hurdles along the way.

So now, the first webpage I'm working on has a rather unusual HTML table on it that’s a bit of a hack and I wonder if Views is capable of making it or if I need to find a different way.

You could call what I’m trying to do a “dynamically indented text display.”

On the current website, the javascript that builds the main part of the HTML table looks like this: '<TR>' + (nLevel == 0 ? '' : '<TD ColSpan="' + nLevel + '"> </TD>') + '<TD ColSpan="' + (13 - nLevel) + '">' + (sHeading == '' ? '' : sHeading + ' ') + (sParty == '' ? '' : '<small>' + sParty + ':</small> ') + (sURL == '' ? '' : '<a HRef="' + sURL + '" target="_blank">' + sLinkText + '</a>') + (sNotes == '' ? '' : sNotes) + '</TD>' + '</TR>' In the data table, every row has (a) a value of nLevel between 0 and 12, inclusive, and (b) either a value of sHeading or a value of one or more of the other text variables. Therefore, every row of the HTML table has either a heading or a text block, and whichever it is is indented by an amount controlled by nLevel.

Two elements of simple logical processing stand out there:

  • The numeric variable, nLevel, determines the level of indentation by a pair of <TD ColSpan=> tags in which the sum of the “ColSpan” parameters is 13. So there are 13 levels of indentation (from 0 to 12) across the page. (On the current page, the width of the indentations is set by 12 repetitions of “<TD width="25">&nbsp;</TD>” in the first row of the table.)
  • A link is constructed from the variables sURL and sLinkText.

I see that Views allows for the calculation of a math expression in the construction of a table, but I don’t see anything that allows for this kind of programming there. So I’m thinking a Views table won’t work, unless there’s something I don’t know.

It’s possible that an HTML list could work if Views allows for nesting of lists, which would control the indentation. When nLevel increases from one row to the next, it always increases by one, so this gives the same behavior as “<UL>” (plus a bullet, which I could live with). But still, I would have to be guiding Views programmatically in its placement of “<UL>” and “</UL>” tags, and I don’t see how I would do that.

Maybe now you can see why I was originally thinking of just translating the code from javascript to PhP and putting that directly on the page. The code is pretty simple, so that would be easy. (The part that I still don’t know how to do is how to connect to the database with a query to get the values of the variables above.) But when I posted my question about whether this was a good idea, I got some strongly worded advice that it’s usually a very bad idea to put PhP code directly on the page.

So what is the right way to get Drupal to do the kind of dynamically indented text display described above?

Thanks for your help.

  • Is indenting HTML code really so important, since the browsers don't make any difference between the HTML output your are trying to get and the one returned from a view? – kiamlaluno Apr 23 '15 at 8:02
  • @kiamlaluno - Sorry, I don't understand the question. Yes, the browser doesn't care, and won't know, whether the HTML was generated by Views or in another way, and I also don't care. My question is, how do I get this HTML generated? In ASP, I generated the HTML dynamically with javascript in the file of the page. In Drupal, I'm being advised not to put executable code (PhP or javascript) directly on the page, but to use modules. I'm not experienced enough yet to be able to whip up a module for this, so is there a way to get the necessary HTML generated with Views or another contributed module? – NewSites Apr 23 '15 at 14:24
0

depending on you exact set up (which you may be able to modify to suit), you could look into Views Tree module:

This module provides a tree-based style plugin for Views. It is equivalent to the tree-based style template from Views 1.

It is based off of the list style. Although it generates a nested view, there is still only a single query run for the view making it quite performant.

| improve this answer | |
0

I think you should consider using the Forena module to address this question. It would be straight forward to transform your HTML table into an equivaent "FRX" file in Forena.

Here is an example of an FRX file (which is an XHTML file):

  <head>
    <title>My custom report title</title>
    <frx:category>Articles related Reports</frx:category>
    <frx:options skin="My_Skin_File_With_CSS_And_JS_To_Beaf_Up_My_Rpt"/>
  </head>
  <body>
    <table frx:block="MyDatabaseConnection/MySqlQuery">
      <tr frx:foreach="*">
      <td>{title}</td>
      <td>{body}</td>
      </tr>
    </table>
  </body>

The documentation that comes with Forena (after you install it), contains all the details you'd need. Here are a few pointers to the demo version of the FRX Reporting Reference (which also gets installed in your own site as part of the Forena installation) that should help:

I wouldn't be surprised if the Report Skins would come in handy also for all sorts of JS and/or CSS requirements you might have also.

Disclosure: I'm a co-maintainer of this module,
I hope this does not violate the site's policy on self-promotion.

| improve this answer | |
  • I've been working again with Forena since you solved the permissions problem yesterday. But now I've run into a timeout problem that has halted progress again. I submitted an issue and hope someone will respond to it so I can keep going to implement what you describe above. Thank you. – NewSites Apr 27 '15 at 8:19
  • I just added a new comment (suggestion that may be worth trying) to that (timeout) issue you submitted, to see if it helps resolve your issue because of the huge volumes you have to process. You can find it at drupal.org/node/2478399#comment-9887287 ... – Pierre.Vriens May 3 '15 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.