Datatables-editor : How to include plugins - datatables

The datatable editor (after the completed purchase of a developer license) avails a slew of additional plug-ins. One such example is "Bootstrap DateTimePicker". However, after following the guide on the page, I could not get the plugin to work.
I've included the external libraries of css and .js files. I've also added the necessary codes to declare the field type as "datetime".
"label": "Updated date:",
"name": "updated_date",
"type": "datetime",
Lastly, I included the additional Plug-in codes (.js) at the header with the rest of the .js script.
On testdrive, the form showed both date and time in text. However, the anticipated "pretty" bootstrap datetimepicker UI does not show.
Can anyone offer any pointers?

Assuming you have included all the correct .js and .css libraries as stated.
You probably just haven't initiated datepicker.
$(document).ready(function () {
... your datatables and editor configuration ...
$('.input-datepicker').datepicker();//<-- Initiates datepicker
//replace '.input-datepicker' with the class of your input element
});

Related

Server Side Rendering Vue with ASP.NET Core 2

I'm trying to understand the usage and limitations of server side rendering with vuejs when using aspnet core.
I used this starter kit for aspnet core and vuejs to setup a simple vue site, which is running based on the code here: https://github.com/selaromdotnet/aspnet-vue-ssr-test/tree/master
I then modified the project to update the aspnet-prerendering and added vue-server-renderer, compiling a hodgepodge of sources to cobble together this update: https://github.com/selaromdotnet/aspnet-vue-ssr-test/tree/ssr
If I run this project, the site appears to load fine, and if I turn off the javascript in the browser, I can see that it does appear that the server-side rendering executed and populated the html result:
however, because JavaScript is disabled, the content isn't moved into the dom as it looks like it is trying to...
My understanding of server-side rendering is that it would populate the html entirely and serve a completed page to the user, so that even if JS was disabled, they'd at least be able to see the page (specifically for SEO purposes). Am I incorrect?
Now I believe modern search engines will execute simple scripts like this to get the content, but I still don't want a blank page rendered if js is disabled...
Is this a limitation of server-side rendering, or perhaps specifically ssr with vue and/or aspnet core?
or am I just missing a step somewhere?
Edit: more information
I looked at the source code for what I believe is the method that prerenders the section here: https://github.com/aspnet/JavaScriptServices/blob/dev/src/Microsoft.AspNetCore.SpaServices/Prerendering/PrerenderTagHelper.cs
The line
output.Content.SetHtmlContent(result.Html);
has a null value for result.Html. However, when I manually edit this value to put a test value, it also doesn't render to the output html, and the app div tag is still empty...
If I'm doing something wrong to populate the result.Html value with the expected output, that's one thing, and I would appreciate some help in doing that, especially since the output html appears to be found, since it's in the script that immediately follows...
However, even if I were to populate it, it appears it's being skipped, as evidenced by me manually changing the value. is this a bug in the code or am I doing somethigng wrong, or perhaps both?
As you correctly noticed, for your project, result.Html inside the tag helper is null. So that line cannot be the location where the output is being generated. Since the HTML output from your prerendering script also does not include a script tag, it is clear that something has to generate that. The only other line that could possible do this is the following from the PrerenderTagHelper:
output.PostElement.SetHtmlContent($"<script>{globalsScript}</script>");
That would fit the observed output, so we should figure out where the globalsScript comes from.
If you look at the PrerenderTagHelper implementation, you can see that it will call Prerenderer.RenderToString which returns a RenderToStringResult. This result object is deserialized from JSON after calling your Node script.
So there are two properties of interest here: Html, and Globals. The former is responsible for containing the HTML output that finally gets rendered inside the tag helper. The latter is a JSON object containing additional global variables that should be set for the client side. These are what will be rendered inside that script tag.
If you look at the rendered HTML from your project, you can see that there are two globals: window.html and window.__INITIAL_STATE__. So these two are set somewhere in your code, although html shouldn’t be a global.
The culprit is the renderOnServer.js file:
vue_renderer.renderToString(context, (err, _html) => {
if (err) { reject(err.message) }
resolve({
globals: {
html: _html,
__INITIAL_STATE__: context.state
}
})
})
As you can see, this will resolve the result containing just a globals object with both html and __INITIAL_STATE__ properties. That’s what gets rendered inside of the script tag.
But what you want to do instead is have html not as part of globals but on the layer above, so that it gets deserialized into the RenderToStringResult.Html property:
resolve({
html: _html,
globals: {
__INITIAL_STATE__: context.state
}
})
If you do it like that, your project will properly perform server-side rendering, without requiring JavaScript for the initial view.

how to handle OPTIONS of SELECT using DOJO

I want write DOJO statement equivalent to following javascript statement:
document.form_name.select_name.options[0]=new Option("Q3","Q4",false,false);
can u help me please!
Dojo is a JavaScript library, so JavaScript is still valid when using Dojo. An alternative would be the use of the dojo/dom-construct module which allows you to create DOM nodes. An example:
require(["dojo/dom-construct", "dojo/domReady!"], function(domConstruct) {
domConstruct.create("option", {
value: "Q4",
innerHTML: "Q3",
defaultSelected: false,
selected: false
}, "test");
});
In this example I create an option based on the settings you provided. The placement of the <option> is based upon the third parameter "test". This means that this option will be placed as the last option of a <select> with an ID called "test".
An example JSFiddle can be found here. There is also a reference guide and the API documentation which might help you.
Pre Dojo 1.7
If you need to make this to work on pre-Dojo 1.7, you need to remove the require() statement since this is a new feature since Dojo 1.7 and is called the AMD loader.
All modules (at least, most of them) have an alternative in pre-Dojo 1.7. dojo/dom-construct would become dojo.create.
dojo/domReady! would become dojo.addOnLoad but this works slightly different than the module (actually dojo/domReady! is a plugin) introduced in Dojo 1.7. I recommend reading the old documentation for more information.

dojo internalize html templates

When using filter and pagination plugins for EnhancedGrid, the HTML templates for the same are loaded from dojox\grid\enhanced\templates.
Is there any way by which I can avoid the server requests for these HTML files by making them part of the Enhanced Grid's inline javascript?
You should make a custom dojo build that creates one js file as a result. follow this instructions from a previous QA:
How to build Dojo into a single file, given a list of dependencies?
EDIT:
The build should add those html files inline, but doesn't. I googled a bit and found this link related to your problem:
http://grokbase.com/t/dojo/dojo-interest/121e536t64/enhancedgrid-filter-problem
It suggests a fix using this link
http://dojo-toolkit.33424.n3.nabble.com/Custom-build-including-CSS-and-HTML-files-td3536573.html
Citation:
If you are using the AMD style of module definition, then you can specify a text dependency like so:
define(["dojo/text!some/file.html", "other/module"],
function(template, otherModule){
...
// to use the contents of the html file, treat template as if it were a normal string
someNode.innerHTML = template;
...
});
The build system should automatically convert the text dependency to an inline string literal. Most Dojo files are already formatted to use this feature, but I can't account for dojox modules. I'm not sure whether similar functionality is possible with the dojo.require/dojo.provide system of dependency declaration.
I have got the solution. Those struglling from this issue pls. note that there is bug with Dojo 1.7.1 and we need to use Dojo 1.8.3 and use internStrings option with the build command. You should see HTML files being interned in the build-report.

Dojo Builds...? What now?

A while back, I looked into a solution for the "flash of unstyled content" when using Dojo and Dojo themes. Someone suggested to combine everything by creating a build, and it'll reduce the load/parse time and remove the need to use preloader overlays, etc.
However, it seems like Dojo is severely lacking in straightforward, "real world" useage examples and tutorials for a lot of its functionality, this especially. A lot of the resources tell you how to set up a build, but not how to implement it.
Let's say I have this in "pageinit.js":
require([
'dojo/parser',
'dojo/dom',
'dojo/dom-class',
//etc...
'dijit/form/ValidationTextBox',
'dijit/form/CheckBox',
// etc...
// Dom Ready call
'dojo/domReady!']
function(
Parser,
Dom,
Class,
// etc...){
// do stuff with parser, dijits, so on.
}
)
Some of the require calls were removed for brevity, but there's a handful of dom requires, style classes, some dijits, etc. When this page loads, there's the flash of unstyled content and then it's fine.
Using the Dojo Web Builder, I selected the modules I'm using, and ran it. It downloaded a zip with a lot of files under it, including a new dojo.js and custom_layer.js.
So my question is now, how do I use these new combined and minified files in place of my "non-build" version? What do I require? Or do I?
So confused...
First, let's understand how the AMD(require/define) API works.
require([
'dojo/parser',
'dojo/dom',
'dojo/dom-class'
], function(parser, dom, domClass){
});
This is going to call the require function, specifying that I need three modules in order to do some work. require will get each module. If will determine if the module has been loaded. If it hasn't it will asynchronously get the file, and load the module into the javascript runtime. Once require has retrieved all of your required modules, it will execute your callback (the function) passing the modules as arguments to the function.
Next, let's understand the build. The dojo build does exactly what you describe. It will compress a bunch of the individual files into a single file. this will make the page load quicker and prevent that 'flash' that you describe.
Finally, putting it all together, you should include the custom_layer.js file along with the dojo.js file.
<script type="text/javascript" src="path/to/dojo/dojo.js" />
<script type="text/javascript" src="path/to/custom_layer.js" />
The web browser will load these two files and evaluate the code. Instead of lazily loading each module in it's own file, the module will already be loaded because it was defined in the custom_layer.js.
So, the answer to your final question is that you should NOT change any of your code based on the specific version of code (source vs custom build) that you are using. Using the AMD api, it should just work.
Not sure if it's best practice or not, but I was seeing the flash of unstyled content when I first started (a few days ago), and saw several examples somewhere that takes care of by just hiding the <body>. Parse will unhide it when it's ready to show something.
<body style="visibility: hidden;">

Google Chrome Extensions, Doesn't Respond to Bookmark Events

I am trying to utilize the Google Bookmarks API for Chrome Extensions (this is not the Google Bookmarks API as in http://www.google.com/bookmarks/, but rather Chrome Bookmarks API).
Anyway, I just tried a simple example which I have the background.html and the manifest.json listed below. However, I am not getting the alert dialog box. I am not getting this problem if I switch to using tab events. What am I doing wrong?
manifest.json
{
"name": "Google Bookmark Integration",
"version": "1.0",
"description": "Integrates Chrome bookmarks with Google Bookmarks.",
"icons": { "128": "images/bookmark.ico" },
"background_page": "background.html",
"permissions": [
"bookmarks",
"http://*.google.com/bookmarks/*"
]
}
background.html
<script>
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
console.log("Bookmark Created");
});
</script>
JavaScript is dynamically typed and function definitions shouldn't have type names. Instead of (string id, BookmarkTreeNode bookmark), you need to write just (id, bookmark). Your background.html should be:
<script>
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
alert("Dialog Box");
});
</script>
In addition, apparently Chrome has limited support for alert() inside extensions. (It worked for me in this particular case, but I've now found other cases where it doesn't.) Try console.log() instead. The Chrome Extensions documentation page on "debugging" has instructions for how to open the Developer Tools / JavaScript console for the background.html page, which you'll need to do.
To answer my own question, the problem here was that, not only do the permissions need to be set to "bookmarks" but they also need to be set to "tabs". Once I did this, the plug-in then recognized adding and removing bookmarks.
Very counterintuitive, but this is the solution.
If you want to see the console.log of the background script, then you need to go to chrome://extensions/ and click on Inspect views service worker and look for the message there.