dynamic searchable fields, best practice? - mysql

I have a Lexicon model, and I want user to be able to create dynamic feature to every lexicon.
And I have a complicate search interface that let user search on every single feature (including the dynamic ones) belonged to Lexicon model.
I could have used a serialized text field to save all the dynamic information if they are not for searching.
In case I want to let user search on all fields, I have created a DynamicField Model to hold all dynamically created features.
But imagine I have 1,000,000,000 lexicon, and if one create a dynamic feature for every lexicon, this will result creating 1,000,000,000 rows in DynamicField model.
So the sql search function will become quite inefficient while a lot of dynamic features created.
Is there a better solution for this situation?
Which way should I take?
searching for a better db design for dynamic fields
try to tuning mysql(add cache fields, add index ...) with current db design

Another idea might be to use MongoDB and MongoMapper, Thinking Sphinx or Solr. Here is Railscast on how to use Mongo: http://railscasts.com/episodes/194-mongodb-and-mongomapper

I think the best way to do this is to use a name/value pairing instead of dynamic fields. Let me explain using the EAV design pattern
So instead of having something like this:
Table: MedicalRecords
<table>
<tr>
<th>Temperature in degrees Fahrenheit</th>
<th>Presence of Cough</th>
<th>Type of Cough</th>
<th>Heart Rate in beats per minute</th>
<th>Column X</th>
<th>Column X + 1</th>
<th>... Column N</th>
</tr>
<tr>
<td>102</td>
<td>True</td>
<td>With phlegm, yellowish, streaks of blood</td>
<td>98</td>
<td>????</td>
<td>????</td>
<td>????</td>
</tr>
</table>
You would design your table like this:
Table: MedicalRecords
<table>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<tr>
<td>Temperature in degrees Fahrenheit</td>
<td>102</td>
</tr>
<tr>
<td>Presence of Cough</td>
<td>True</td>
</tr>
<tr>
<td>Type of Cough</td>
<td>With phlegm, yellowish, streaks of blood</td>
</tr>
<tr>
<td>Heart Rate in beats per minute</td>
<td>98</td>
</tr>
<tr>
<td>Column X</td>
<td>????</td>
</tr>
<tr>
<td>Column X + 1</td>
<td>????</td>
</tr>
<tr>
<td>... Column N</td>
<td>????</td>
</tr>
</table>
(Tried to get the table tags to work but couldn't Try coping my code into an html file to get the idea.)

Related

Html table with yes/no data?

I need to create an HTML table for a website that has binary yes/no data. I also need a 'yes' to be styled with a tick.
For instance Billy does have a drivers licence, but does not live in London. I need my table to look like this:
Is this a semantically correct solution?
http://jsfiddle.net/
<table>
<thead>
<tr>
<th>Name</th>
<th>Has drivers licence?</th>
<th>Lived in London?</th>
</tr>
</thead>
<tbody>
<tr>
<td>Billy</td>
<td>Yes</td>
<td></td>
</tr>
<tr>
<td>Alex</td>
<td></td>
<td>Yes</td>
</tr>
<tr>
<td>John</td>
<td>Yes</td>
<td></td>
</tr>
</tbody>
</table>
Would it still be semantically correct to use ✓ instead of 'Yes'? I need this data to be editable by the CMS so I cant style the tick with a CSS class.
You could use the abbr tag, to describe the ✓ for screenreaders..
<td><abbr title="Yes">✓</abbr></td>
Here is another Question concerning this issue:
How to target a braille / screen-reader via CSS

Table representation using css

Consider the scenario like this.
I have Array List of string arrays.
I want to represent them in the image shown below.
currently I have implemented this as Table. But this is not dynamic. Going forward I have to loop twice which seems some what difficult.
<table>
<tr>
<td>Pack1</td>
<td>Ch1</td>
</tr>
<tr>
<td></td>
<td>ch2</td>
</tr>
<tr>
<td>Pack2</td>
<td>val1</td>
</tr>
<tr>
<td></td>
<td>val2</td>
</tr>
</table>
Please let me know any other approach using css styles.
Loop through every pack
Again loop through each pack to get the values.
This will likely be a little bit of a hot-potato as it's not entirely clear what you want exactly though I've posted a bit of a more structured table format that seems to resemble your goal. If you know how to use colspan and rowspan then you can adjust the table (e.g. if you want multiple rows on a single column) though consider how tables are intended and mostly style by default. I've added some CSS and text to help give you an idea of how (X)HTML tables work when you take advantage of things.
As far as looping I think you can apply the idea of "packages" to tbody elements that are like partitions of a table...they're part of the same kind of data though have their own separate groups.
Comment if you need help adjusting this, it's not difficult.
<table summary="Describe your table here." style="border: 1px solid #aaa; border-collapse: collapse; width: 40%;">
<thead style="background-color: #f77;">
<tr><td colspan="3">Table Header</td></tr>
</thead>
<tfoot style="background-color: #f77;">
<tr><td colspan="3">Table Footer</td></tr>
</tfoot>
<tbody>
<tr style="background-color: #fcc;"><th colspan="3">Pack 1 (Tbody Header)</th></tr>
<tr><td>One</td><td>Two</td><td>Three</td></tr>
<tr><td>One</td><td>Two</td><td>Three</td></tr>
<tr><td>One</td><td>Two</td><td>Three</td></tr>
</tbody>
<tbody>
<tr style="background-color: #fcc;"><th colspan="3">Pack 2 (Tbody Header)</th></tr>
<tr><td>One</td><td>Two</td><td>Three</td></tr>
<tr><td>One</td><td>Two</td><td>Three</td></tr>
<tr><td>One</td><td>Two</td><td>Three</td></tr>
</tbody>
</table>

Formatting of html tables in GSP

I am using Grails and I am currently faced with this problem.
This is the result of my html table
And this is my code from the gsp page
<tr>
<th>Device ID</th>
<th>Device Type</th>
<th>Status</th>
<th>Customer</th>
</tr>
<tr>
<g:each in = "${reqid}">
<td>${it.device_id}</td>
</g:each>
<g:each in ="${custname}">
<td>${it.type}</td>
<td>${it.system_status}</td>
<td>${it.username}</td>
</g:each>
</tr>
So the problem is, how do I format the table such that the "LHCT271 , 2 , Thomasyeo " will be shifted down accordingly? I've tried to add the <tr> tags here and there but it doesn't work.. any help please?
I think you problem is not in the view, but in the controller (or maybe even the domain). You must have some way of knowing that reqid and custname are related if they are in the same table. You must use that to construct an object that can be easily used in a g:each
You are looking for a way to mix columns and rows, and still get a nice table. I'm afraid that is not possible.
Edit
(Sorry, I just saw the last comment.)
You cannot mix two items in a g:each.
Furthermore, if the two things are not related you probably must not put them in the same table. There will be no way for you or for Grails, to know how to properly organize the information
Do you want to display the first reqid against the first custname (three fields), the second againts the second and so on? And are those collections of same length?
In such case you could try the following:
<tr>
<th>Device ID</th>
<th>Device Type</th>
<th>Status</th>
<th>Customer</th>
</tr>
<g:each var="req" in="${reqid}" status="i">
<tr>
<td>${req}</td>
<td>${custname[i].type}</td>
<td>${custname[i].system_status}</td>
<td>${custname[i].username}</td>
</tr>
</g:each>

is it semantic/acceptable to put paging (NEXT/LAST, etc) links in a <tfoot> of a statistical table element?

having trouble deciding whether or not it makes sense to put paging information about a stats table in a <tfoot> element of the table.
information like "Page 1 of 13" and links to "next" & "prev," etc.
w3c <table> reference & examples don't do <tfoot> justice, IMO.
so, doing something like:
<table>
<caption>Stats Table!</caption>
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3">
prev pg next pg
</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>x</td>
<td>y</td>
<td>z</td>
</tr>
</tbody>
with some minor styling looks like this (click for example on jsfiddle)
does this seem to fit into proper semantics of html tables? any references as to why or why not?
I would say yes, that would be acceptable.
Traditionally, the <tfoot> is usually used to duplicate header information when a table must be broken across boundaries (think printed pages and things of that nature). It also can be used as a static footer when the <tbody> elements are rendered in a scrolling panel. I believe that is close enough to what you're trying to do.
As a side note, I'm glad to see you've placed the <tfoot> before the <tbody>. I can't begin to count how many times I see people put it at the bottom.
In general I agree with the accepted answer, but there's one exception: If you are on a small screen device and use overflow-x: auto for horizontal scrolling of the table, then you may (or may not) want your prev/next actions to stay visible - independent of the horizontal scroll position of the table.

Making html-table work as an Excel document

I'm working on an order form to a bookshop-website. It's just like a normal table in HTML and I wonder how to make a cell calculate other cell's value and display the sum of it. As it works in Excel.
I get order sheets like these all the time from my wholesale vendors. I personally don't offer this because I have multiple price points for my wholesale customers and I'd rather not manualy verify that the prices in the spreadsheet are in fact the price that they pay. So I'd definately recommend that you do this server side ultimately.
I didn't know this until I just tried it, but you can actually just make a table with the literal Excel formulas in them. You can then either
ctrl+c it into a new spreadsheet.
Send it down as an Excel spreadsheet via something like ASP.Net Response.ContentType.
Change the extension to .xls.
I did this with this example html and it works:
<html>
<head>
<title>test</title>
</head>
<body>
<table>
<tr>
<th>Item</th>
<th>Qty</th>
<th>Price</th>
<th>Extended</th>
</tr>
<tr>
<td>Jasper's Jasper</td>
<td>2</td>
<td>$7.50</td>
<td>=(B2*C2)</td>
</tr>
<tr>
<td>Widget</td>
<td>5</td>
<td>$2.10</td>
<td>=(B3*C3)</td>
</tr>
<tr>
<td colspan=2>Totals</td>
</tr>
<tr>
<td></td>
<td></td>
<td>Total</td>
<td>=SUM(D2:D3)</td>
</tr>
</table>
</body>