Dandelion Datatables + Thymleaf + dt:format - datatable

I've tried to implement the formatting attribute for Dandelion Datatables as specified here using Thymeleaf to no avail, like so:
<table dt:table="true" dt:serverside="true" dt:url="#{/somefnplace}">
<thead>
<tr>
<th dt:property="someCurrencyField" dt:format="{0, number, #.##}">
</tr>
</thead>
</table>
...but this does not do anything. Anyone got an idea on how this is supposed to work, or do I have to create render functions for every column because this feature is broken?

Unfortunately, the dt:format attribute is not compatible with AJAX sources. See the last column of the link you've mentioned.
In the upcoming version, it will simply be removed, because using DOM sources, expression utility objects meet all needs perfectly.
So yes, currently the only way is to use the dt:renderFunction attribute, which will refer to a rendering function, one for each column to need to display in a specific format.

Related

Pull data from a table, where the website constantly enters new data into table [duplicate]

This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
I am trying to get the data of a table into Google Sheets. The table on the website constantly gets new data added to to the top. (Latest trade data). I am really new to web scraping and HTML code. I'm not even sure if I am looking at the right HTML element or if I should be looking at XPATH for ImportXML.
The URL is: https://www.deribit.com/main#/options?tab=all
XPATH: //*[#id="tradesScrollC"]
Element: <div id="tradesScrollC" class="table-scrollable-deribit" style="max-height: 200px;overflow-y: auto" onscroll="BTCOptions.scrollTradesC(event);">
<table class="table table-hover table-condensed table-nopadding" float-thead="floatTheadOptions">
<thead>
<tr>
<th ng-i18next="app.assets">Assets</th>
<th ng-i18next="app.price">Price</th>
<th ng-i18next="app.imp_v">IV</th>
<th ng-i18next="app.Qty">Qty</th>
<th ng-i18next="app.time">Date Time</th>
</tr>
</thead>
<tbody id="last_trades_call"></tbody>
</table>
</div>
I have tried both importXML and importHTML, however, I am not sure what each tag is and if I'm using it correctly.
=IMPORTXML("https://www.deribit.com/main#/options?tab=all", "//div[#id='tradesScrollC']/table")
I would like to print all the trade data as it updates on the website, to also print on my google sheet. With column headers exactly like the website (Assets Price IV Qty Date Time)
it is not about formula but website. you will need to find a different one because Google Sheets is not able to scrape JavaScript content. you can check this simply by disabling JS for a given site and you will see a blank page like:
this is all you can get:
=ARRAY_CONSTRAIN(IMPORTXML("https://www.deribit.com/main#/options?tab=all", "//*"), 1000, 10)
=ARRAY_CONSTRAIN(IMPORTDATA("https://www.deribit.com/main#/options?tab=all"), 1000, 10)

WYSIWYG HTML editor that doesn't try and fix bad HTML

I need a WYSIWYG HTML editor that can edit PHP Blade and Handlebars* templates. I've tried TinyMCE, CKEditor and bootstrap wysihtml5 but they all "fix" my invalid HTML. Can anyone suggest an alternative?
I need to be able to toggle between WYSIWYG and Source mode without the following being altered.
<table>
<thead>
<tr>
<tr>Column 1</tr>
<tr>Column 2</tr>
</tr>
</thead>
<tbody>
#foreach ($data as $datum)
<tr>
<td>{{ $datum->col1 }}</td>
<td>{{ $datum->col2 }}</td>
</tr>
#endforeach
</tbody>
</table>
All the editors I have found remove the #foreach and sometimes break the table too. I don't care too much if the "visual" mode is broken but I need the HTML to remain untouched.
*I prefix Handlebars variables with $ so they're broadly compatible with blade templates.
You can use CKEditor for that, however you will have to define which parts of the code you DON'T want the editor to fix.
CKEditor have the protectedSource feature which you can use to define the parts of the source that the editor should not touch, even if they are not valid HTML.
I've created an example that will work with your #foreach loop and the variables in your example. You can take it and enhance it to fit your needs:
CKEDITOR.editorConfig = function( config ) {
....
....
config.protectedSource.push( /#foreach.*/g );
config.protectedSource.push( /#endforeach.*/g );
config.protectedSource.push( /{{.*}}/g );
}
Here is a working fiddle you can check: https://jsfiddle.net/0tw75xt3/
Note that I changed the
<tr>
<tr>Column 1</tr>
<tr>Column 2</tr>
</tr>
since it's not a valid HTML and I guessed it wasn't supposed to be <tr><tr>
If you want to support more complex templates you will need some more complex regular expressions inside the protectedSource, however this can really give you a good place to start.
There were some WYSIWYG editors for React, that I was able to find.
https://github.com/Pagedraw/pagedraw
https://github.com/c8r/lab
Demo of Pagedraw on YouTube.com, https://www.youtube.com/watch?v=NjH3koR1E6w
I read about the idea about WYSIWYG editing of components in https://medium.com/#vlascik/ember-in-the-middle-of-2019-the-good-the-bad-the-ugly-hopefully-d641cc73d6d1:
https://pinegrow.com
https://grapesjs.com/
Pinegrow explicitly disavows this in the documentation, https://pinegrow.com/docs/pages/pages.html#formats
I saw an attempt to get Handlebars working with GrapesJS, but it ended up inconclusively, https://github.com/artf/grapesjs/issues/1162

Excel VBA to Deal With AJAX

I am practicing to use excel vba to download information from website: http://mops.twse.com.tw/mops/web/t05sr01_1
But I have no idea how to download the data behind click button, as the image shown: http://i.stack.imgur.com/KZHiZ.jpg
I excerpt its web code as below. Could anyone explain me how to code in excel vba to get its data?
Thank you very mush.
Web code:
<td style='text-align:left !important;' nowrap>鴻海</td>
<td style='text-align:left !important;'>105/01/05</td>
<td style='text-align:left !important;'>11:41:00</td>
<td style='text-align:left !important;'>說明媒體報導</td>
<td><input type='button' value='詳細資料' onclick="document.fm_t05sr01_1.SEQ_NO.value='1';document.fm_t05sr01_1.SPOKE_TIME.value='114100';document.fm_t05sr01_1.SPOKE_DATE.value='20160105';document.fm_t05sr01_1.COMPANY_NAME.value='?E??';document.fm_t05sr01_1.COMPANY_ID.value='2317';document.fm_t05sr01_1.skey.value='2317201601051';document.fm_t05sr01_1.hhc_co_name.value='?E??';ajax1(this.form,'table01');">
You haven't shown how you are getting the html.
You can use a CSS selector.
General for first input button
input[type=button]
This says element(s) with input tag having attribute type whole value is 'button'
You apply with the querySelector method, or querySelectorAll if more than one match and then use index for required element.
ie.document.querySelector("input[type=button]").Click
If in an HTMLDocument variable e.g. htmlDoc then
htmlDoc.querySelector("input[type=button]").Click

View component of MVC. Should I pre generate HTML tag elements in the Controller for the View?

I'am currently creating a MVC Java Web App with Struts2.
One element of my app is searching for some results via form. When the user submits the form an Action gets the necessary values from the database and populates a Map:
Map<Integer,List<String>> values = new HashMap<Integer,List<String>>();
Which has a list of column values for each row.
By Following this approach I can have generic JSP for displaying the results of any resultbox:
<s:div cssClass='resultContainer'
cssStyle=' min-height: 150px; max-height:%{header}px; overflow: auto; %{display}; '
theme="qxhtml">
<table id='resultTable'>
<tr id='tableHeader'>
<s:iterator value="headers">
<th><s:property /></th>
</s:iterator>
</tr>
<s:iterator value="values">
<tr class='results'>
<s:iterator value="value">
<td><s:property escape="false" /></td>
</s:iterator>
</tr>
</s:iterator>
</table>
I feel now that this is a bad approach. Instead I should change the Map to a List of ResultBoxRow objects. Each ResultBox will have its own View Jsp instead of one generic one allowing me to iterate over the objects and output for example:
<s:iterator value="value">
<td><s:property name="firstname" /></td>
<td><s:property name="lastname" /></td>
etc.
In the case of the table headers I may need to give certain headers individual style properties. I feel these should be defined in the JSP itself rather than get the JSP to reference a value from the controller containing the style for that header.
I think my overall question is how much should the controller control the style/display of elements of the View? I feel it should just generate the individual elements displayed in the tags but not the values to put in the "style" tag of the row for example. Even if this does sacrifice a simple single JSP to handle every result box.
It would be great to get your opinions.
The controller should have nothing to do with the display mechanism: that's the point of MVC, to completely separate the data from its presentation.
You can still DRY up the view layer via custom tags, includes, templates, etc. Styles may be passed as attributes, while the underlying DOM would be created by a single page or template.
It also matters what the nature of the attributes you want to pass. If they're semantic that could logically from from the model or controller that's fine. If they're purely presentational, like colors, widths, etc. then it has no business in the model or controller.

hidden attribute for th in dojo datagrid is not working into firefox 7+

hidden attribute to hide a column in dojo datagrid is not working into firefox 7.0.1, that particular column is hided permanently without depending on the value of hidden attribute.
I tried with setting different values to hidden :-
1) hidden="true"
2) hidden=true
But this attribute is working fine in old firefox version 3.6.15.
I am doing something like this :-
<table dojoType="dojox.grid.DataGrid" id="tableGrid" height="300px" >
<thead>
<tr>
<th field="first_column" width="auto" hidden="true">First Columnn</th>
</tr>
</thead>
</table>
So I was wondering if I am doing something wrong. Also please let me know if there is any other way also to hide the column.
Thanks
Neeraj
That sounds like this defect in the dojo bug tracker: http://bugs.dojotoolkit.org/ticket/11957
If you're not averse to patching your dojo source, there's a patch attached to the ticket that should resolve the issue. It hasn't been applied to any Dojo version yet though.

Resources