Function didParseCell is called twice - jspdf-autotable

I've paid attention that function in didParseCell hook is called twice. Why is it happening and how can I prevent it?
For example, I've checkedit also for this simple table:
let doc = new jsPDF()
doc.autoTable({
body: [[1]],
didParseCell: data => {
console.log(data.cell.text)
}
})
doc.save('table.pdf')
Function in didParseCell is called for all cells and then called again for all cells. Why does it happen?
Thank you!

Related

How does this function keep track of clicks?

On the "Thinking in Compose" page I don't get this code, how does $clicks keep track of number of clicks?
#Composable
fun ClickCounter(clicks: Int, onClick: () -> Unit) {
Button(onClick = onClick) {
Text("I've been clicked $clicks times")
}
}
I'm learning Kotlin at the same time as Compose, so I get puzzled all the time.
It's omitted in that example but it should store the click-count in a MutableState<T> wrapped with remember
var clickCount by remember { mutableStateOf(0)}
ClickCounter(clicks = clickCount, onClick = {clickCount += it})
For real real real beginner like me, let me add my comment and code.
When the ClickCounter composable is called we need to pass two parameters.
To 'clicks', we pass initial value 0 which will be changed everytime we click the button. Also the initial value need to be 'remembered' and tracked for further changes. So we create new variable using 'mutableStateOf' function inside 'remember' function.
To 'onClick', we need to pass function which adds 1 everytime the button is clicked.
As a caller of the ClickCounter composable, I made a simple preview composable as below.
#Preview(showBackground = true)
#Composable
fun ClickCounterPreview(){
var clicks by remember { mutableStateOf(0) }
// We call ClickCounter composable passing two parameters.
ClickCounter(clicks = clicks, onClick = { clicks += 1 })
}

How can I clear a write("message")

Basically, I have a button that write("message"+myVar).
Then I want to press a button that will delete the written message, but not mess with the variable at all.
I am very new to coding. I code on Code.org which is powered by javascript.
Much thanks
Welcome to SO. Always try to share your code so anyone can help you better. As much as I understand there are lots of ways to achieve this. The most straightforward one could be to create a textLabel with an empty string and then modify it with the setText property of code.org. Like so;
var myVar = "something";
textLabel("messageId","");
button("createButton", "create");
onEvent("createButton", "click", function( ) {
setText("messageId", "message" + myVar);
});
button("deleteButton", "delete");
onEvent("deleteButton", "click", function( ) {
setText("messageId",myVar);
});

SAPUI5 Table Cell Custom Control Binding

I was wondering if someone could shed some light on the issue I am having. I can't seem to get the data model updated when I use my custom input control in a cell. When using the standard sap.m.Input, updates to the data model are performed properly.
Here is the Plunker: https://plnkr.co/edit/GxE6F8DbW9DHqWjpfdO0
I have overrriden the getter for the 'value' properly to get the data from the entry field. Debugging in Chrome shows that this function is not called which I believe is the reason the data model is not updated.
getValue: function() {
var me = this;
var ef = sap.ui.getCore().byId(me.sId + '-ef');
return ef.getProperty('value');
}
Basically, there is a table with two rows and four columns. The first column uses my custom input. The second column has a custom button with an aggregation (additionalParameters) containing the bound data used in the first column. The third column uses a standard sap.m.Input and lastly the fourth column is again a custom button with the 'additionalParameters' aggregation bound to the data in the third column. When any of the buttons are pressed it fires an event which in turn updates the 'Sample' input field.
So, when I type something in the first column, tab out and press the respective 'PB1' button, only the original data from the model appears in the 'Sample' input field. If I type something in the third column, tab out of the field and press the respective 'PB2' button, the 'Sample' input field is properly set by the newly entered data implying the data model has been updated.
Edit
I can get the value from the Input no problem. Maybe I can clarify. The 'MyCustomInput' in cell 1 has 'value' bound to 'list>colOne'. The 'MyCustomButton' in cell 2 has the 'text' of the first item in aggregation 'additionalParameters' bound to the same 'list>colOne'. Any text entered into MyCustomInput does not update the model and thus does not update the 'additionalParameters' item. If I do the exact same thing but use a standard Input instead of MyCustomInput it works. As can be seen with the Input in Cell 3 and the button in Cell 4.
Thank you
May be you can provide more information. We have a simple example here
http://jsbin.com/yukujag/edit?html,js,output and it works on with getValue and setValue
sap.ui.define(['sap/m/Input', 'sap/m/Button', 'sap/m/VBox'],
function(Input, Button, VBox) {
Input.extend('MyInput', {
value: 'abc',
renderer: {},
getValue: function() {
return this.value;
},
setValue: function(v) {
this.value = v;
},
});
var oInput = new MyInput();
var oBox = new VBox({
items: [
oInput,
new Button({
text: 'Test',
press: function() {
alert(oInput.getValue());
}
})
]
})
oBox.placeAt('content');
});
Thanks
-D

MVC Kendo UI Grid - call function after all the rows have been expanded

I am using the ASP.NET MVC Kendo grid.
On click of a button, I need to expand all the rows.
Here is the code for the same:
var row = $(this).closest("tr.k-master-row");
grid.data("kendoGrid").expandRow(row);
Where this and grid have been defined. This works well.
On expand of each row, the following event is called (for each row), as the detail template is bound:
.Events(events => events.DataBound("onInnerGridDataBound"))
function onInnerGridDataBound(e) {
//Do something here
}
My requirement is that after I initiate the call to expand all the rows, I have a few lines in the code, which should be executed only after all the rows have been expanded. So,
function expandAll()
{
var row = $(this).closest("tr.k-master-row"); //Step1
grid.data("kendoGrid").expandRow(row);"); //Step2
//Do something after the onInnerGridDataBound event is called for
every expanded row.
..................................
//Ideally should be step 4 to be executed, but executes immediately
//after step2
}
//Ideally Step 3 to execute, but executes last
function onInnerGridDataBound(e) {
//Do something here
}
I want to avoid using the setTimeout method, as I don't know how long it will take or any flags.
Hope to find an answer soon.
Thanks!
Have you tried this?
Not sure if it'd work here but it should be something like:
$.when(grid.data("kendoGrid").expandRow(row))
.done(function () {
//after completing expandRow event
})
.then(function() {
//something else
});
Again, this may not work at all since I'm not sure if kendoGrid events can be treated as deferred objects but it's worth a shot.

Add an event to HTML elements with a specific class

I'm working on a modal window, and I want to make the function as reusable as possible. Said that, I want to set a few anchor tags with a class equals to "modal", and when a particular anchor tag is clicked, get its Id and pass it to a function that will execute another function based on the Id that was passed.
This is what I have so far:
// this gets an array with all the elements that have a class equals to "modal"
var anchorTrigger = document.getElementsByClassName('modal');
Then I tried to set the addEventListener for each item in the array by doing this:
var anchorTotal = anchorTrigger.length;
for(var i = 0; i < anchorTotal ; i++){
anchorTrigger.addEventListener('click', fireModal, false);
}
and then run the last function "fireModal" that will open the modal, like so:
function fireModal(){
//some more code here ...
}
My problem is that in the "for" loop, I get an error saying that anchorTrigger.addEvent ... is not a function.
I can tell that the error might be related to the fact that I'm trying to set up the "addEventListener" to an array as oppose to individual elements, but I don't know what I'm supposed to do.
Any help would be greatly appreciated.
anchorTrigger[i].addEventListener...

Resources