Bootstrap-table override table export function - bootstrap-table

I am using Bootstrap-table and I would like to export my table data to an Excel file.
I like the icons used by the bootstrap-table-export plugin and I want to use that, but I want to call my own export function for custom formatting.
In the bootstrap-table-export.js, there are a bunch of key-value pairs of strings and functions.
The one I am interested in is:
key: "exportTable",
value: function exportTable(options) {
var _this2 = this;
... code that does export....
I can alter the source to just call my code here, but I would like a way that is compatible with future versions. Can the key-value pairs be altered to override the "exportTable" function with my own code?
The documentation at https://bootstrap-table.com/docs/extensions/export/#exporttable gives me a clue that the exportTable function can be overridden. Is this the case?
Thanks!

Related

How to get on a Bokeh callback which Object has triggered the callback?

I´m building some bokeh plots functions that, depending on the structured of the supplied data, will have different quantity of Select widgets.
This way, I have a list called 'filters' that contains each Select widget as a list element:
filter = [Select1, Select2, ....]
I´m assingning to each of these function a same callback 'update_dropdown', as code bellow. For the last filter, I finally assign a callback for 'update_plot'.
for f in filters[:-1]:
f.on_change('value', update_dropdown)
filters[-1].on_change('value', update_plot)
However, for this strategy to be effective I need to get which of the filters has triggered the 'update_dropdown' callback inside the 'update_dropdown' function for it to update the other filters accordingly. IS it possible to accomplish it?
I would expect something like this:
def update_dropdown(attr, old, new, FILTER_WHO_TRIGGERED_THE_CALLBACK):
#doing some stuff here accordingly to the variable FILTER_WHO_TRIGGERED_THE_CALLBACK
Thanks!!!!
There's no way to do it directly - you have to create a separate callback for each filter.
Something like:
def bind_cb_obj(cb_obj, cb):
def wrapped(attr, old, new):
cb(cb_obj, attr, old, new)
return wrapped
filters[-1].on_change('value', bind_cb_obj(filters[-1], update_plot))

How to import keys and values into variables from a map?

I need to export the keys and values from map in Dart. In PHP I use for that purpose function extract():
$array=array('one'=>1,'two'=>2,'three'=>3);
extract($array);
But I don't know, how to do the same thing in Dart. Is there any special function or construct for it? Or how can I reach the same result with forEach()? Is there anybody, who could help me?
Update 1: My target is from the map like this, but much complicated (example taken from Dart up and running):
var gifts = {
// Keys Values
'first' : 'partridge',
'second' : 'turtledoves',
'fifth' : 'golden rings'
};
in which I want to rewrite the result by any simple function or forEach() loop:
// something like gifts.forEach()? but how?
into variables:
assert(first=='partridge');
assert(second=='turtledoves');
assert(fifth=='golden rings');
//wow, rewritten! The code can continue and use just the variables:
querySelector('#animal').text=first;
Dart is a statically declared language. You cannot create new variable names at runtime, from a map or in any other way.
In order to refer to a variable, it must already be declared. That means that even if you could introduce new variables, you could not have any references to it in your existing code.
If the variables are already declared, and you just want to assign the values to them, you can use the mirror system, but I wouldn't recommend that. It is much simpler to just access the values directly in the map.

Detect template change in Meteor

I'm looking to make an element flash on screen when the underlying collection is updated.
It seems to me that it would make to have an equivalent of Template.my_template.rendered = function(){} which is fired every time the template is updated.
Ideally, this function would not fire the first time the template is rendered.
This is seems like such an obvious use case, am I missing something?
For Meteor < 0.8
You should use Template.myTemplate.created to do something for the very first time. From the docs Template.myTemplate.rendered is fired everytime there is a change including the first time. If you want to limit it to only the second time and changes after that (I'm guessing this is what you want), you have to write some custom logic. Currently there is no Meteor api that supports that.
For Meteor-0.8
It seems like this API underwent some backwards incompatible changes in Meteor-0.8.
There is an elegant way to achieve this as described Adaptation to the new Meteor rendered callback here. Bascially you should modify whatever function you are attaching to the variables inside your Template's javascript by calling a helper function once. For example,
var renderCount = 1;
var myHelper = function () {
console.log("rendered #" + renderCount);
renderCount++;
};
Template.myTemplate.myVariable = function () {
myHelper();
return this.name;
};
Hope this helps. There is also another alternative approach in that same repo. You might like that one.
There is no simple solution; more discussion here: https://groups.google.com/forum/#!topic/meteor-talk/iQ37mTP3hLg

RequireJS loads a .js, but is inline code still async?

From what I have seen using a debugger, calling:
require(["menu/main-menu"], function(util) {
Will load the main-menu.js file, but the function is called before the global code in the required .js file is executed? Is this correct?
If so, what is the best way to have all that code executed before my function is called?
The problem I am trying to solve is I want the code in mani-menu.js to all be in a module. But I can't call any method in that module until the global code in there is executed which creates the module.
I can call a global method in there which then creates everything, but that then requires a global init() method in every .js file (each with a unique name).
What's the best way to handle all this?
Update: There's a more basic question here (maybe). In writing javascript (and I use Sencha Ext JS & TypeScript), I need to create my objects. So when I go to create say my main menu, I want to call a method in my main-menu.js file to get that Ext JS derived menu object I created.
I think all the code in main-menu.js should be in a namespace, including the method I call to get the menu object. Is that correct? In addition, the way most Ext JS code is set up is you have several Ext.define() calls as well as other variable instantiations, and then the function that takes all that, builds the full menu, and returns it. But that requires all that code has executed in main-menu.js before I call it.
Am I approaching this correctly? My experience to date is Java & C# and I may be trying to fit that model incorrectly to javascript.
Let's suppose menu/main-menu.js contains this:
define(function () {
// Module factory function
return [... whatever you want to expose...];
});
And your application does this:
require(["menu/main-menu"], function (util) {
// Require callback.
});
What happens is:
The require call loads menu/main-menu.js.
The define in menu/main-menu.js is executed.
The module factory function (the function passed to define) is executed.
The require callback is executed with the symbol util set to
what the factory function in menu/main-menu.js returned.
As for simulating namespaces, there are multiple ways to do it. For
instance, you can do it like this:
define(function () {
return {
foo: function () {},
bar: function () {},
[...]
};
});
This exports an object with two functions in it. You can then use it
like this:
require(["menu/main-menu"], function (util) {
util.foo();
util.bar();
});
RequireJS also supports a CommonJS-style of defining modules:
define(function (require, exports, module) {
exports.foo = function () {};
exports.bar = function () {};
[...]
});
This is functionally equivalent to the first way I defined the module
earlier: you get the same two functions and you use them in the same
way as I've shown above.
Unfortunately, I can't speak about Ext JS specifically because I don't
use it.

How to read xml tags and its data using flex?

I need to read xml tags and its datas from one file and then write it to another xml..how to do it?? please let me know immediately...?
See http://livedocs.adobe.com/flex/2/langref/XML.html . I find it hard to believe you googled this before asking.
You can use the FileReference.save() method to save XML data to a local file. It will prompt the user for a location to save the file first and then save the data.
Here's an example:
var xml:XML = <root><someXmlTag/></root>;
var fileReference:FileReference = new FileReference()
fileReference.save(xml, "myfile.xml");
As far as I knew, Flex wasn't able to write to files!
I use a HTTPService to load the XML file and a result even handler to access it.
<mx:HTTPService id="service" url="myXml.xml" result="ServiceResult (event)"/>
Do not specify a result format in the HTTPService tag.
This is the code for the result event handler.
private function ServiceResult (e : ResultEvent) : void {
e.result.XmlTag.AnotherXmlTag;
}
You can also use service.lastResult to access the last result returned by the HTTPService. The result is fully compatible with the dataProvider property, especially in arrays and chart series.
var series : LineSeries = new LineSeries ();
series.dataProvider = e.result.XmlTag.AnotherXmlTag;
This will take the value in all AnotherXmlTag tags within XmlTag. For series, though, you should also specify either a yField or and xField, but it digress :-)
If it doesn't work, you can also cast it using the as keyword, example:
series.dataProvider = e.result.XmlTag as ArrayCollection;
I haven't actually tried casting it in this scenario, but the bottom line is that XML tags are vary compatible with arrays and ArrayCollections.
In your case, you would just use e.result to get the complete XML file, assign it to a variable, and write it using Ben's method. You can also create an array from individual values using the way I explained above, and manually insert tags and such if you need. The advantage of this is that you have all the values ready in an array would you need them later on. If you loop through the indices, this won't require a lot of work, and it would be the way I'd do it.
Hope this helps!

Resources