Save data into sql server using custom method in lightswitch html client - javascript

How to save data on button click(not by using save icon given by popup screen). I tried to use custom method like below. but data is not saving in sql database.
myapp.AddEditApplicantDeclaration.SubmitMethod_execute = funcation(scree)
{
msls.application.commitChanges().then(null, function fail(e) {
alert(e.message);
msls.application.cancelChanges();
throw e;
});
};
I created a button and write the _execute method. but its not saving into data base. Am i missing something here.
Its a simple table and trying to update isSummitted column into "Applicant" table.

I save the data by simply using myapp.commitChanges(); ... this can be included within validation under the _execute of a button as you have above

Related

save filters, no data WebDataRocks

I have a table that receives a .JSON.
I have created some filters and I would like to save them but without saving the information that I received at that time with the filter.
I already tried:
pivot.getData({},
function(data) {
console.log(data);
},
function(data) {
console.log(data);
}
);
Too
var report = pivot.getReport();
console.log(report);
by last
pivot.save({filename:'reporte.json',embedData : false });
Thanks for your help
There are several ways to achieve what you need:
You can still use:
var report = pivot.getReport();
the data information is stored in report["dataSource"]. In such a
case, you can easily remove the unnecessary object the following
way:
delete report["dataSource"];
After that, the JSON config is saved as a file to the disk using
the following approach:
JavaScript: Create and save file.
The disadvantage of such a solution is that you cannot use the saved
JSON config to restore the view since it lacks the data part. You will need to add the "dataSource" part when you decide to restore
the view. Therefore, the solution that described below looks better
for me.
You can create a web service that returns the data file or simply put the JSON data file to the server. In such a case,
WebDataRocks will load the data for you. Then, when you decide to
save the config, only the link to the data will be saved to config.
Here is the reference to docs:
https://www.webdatarocks.com/doc/data-source-object/. The
"filename" property represents the link which leads to your data
file.
In such a case you don't need any additional customization for the
"Save" functionality. You can use a default one. Then it is easy to restore the view using the saved config.

Passing a JavaScript object from my form to my Node app

I have this jQuery code that gets data from my form. I used a console statement to see the value. However I want to pass the data to my Node application so that I can insert into a database.
$(function() {
$('#kiosk_signin').submit(function() {
var data = $('#kiosk_signin :input').serializeArray();
console.log(data[0]);
});
});
Please let me know what I need to do.
Assuming you are using express, posting this to your route.., and inserting into the DB..
You would do something like this in your routes..
router.post('/whereever', function(req,res,next(){
///assuming kiosk_signin is the name of an input field
///and the action is ='/whereever' method='post'
var data = req.body.kiosk_signin
console.log('if you want to log it', data)
db.insert({propert: data}).then(function(){
res.redirect('/home')
})
})
I don't use JQuery for submitting forms if I have a full-stack app, just because I intend on sending it directly to the server. Hopefully that helps..

Datatable client-side data change/redraw

I set up a datatables that initially gets from server some data and represents it, but then everything is left to the client. Some options are:
serverSide: false,
sAjaxSource: mySource,
My $.fn.DataTable.version is 1.10.2.
Then I need to change, client-side, the aaData under the table because some working on data is performed. I need to update the DT to show the client-altered temporary data without send another request to server (for two reason: prevent useless traffic and because that data is being altered).
I am looking for a way to edit the underlying DT databean to edit it, so then calling again
myTable.draw();
on my table I obtain a refresh realtime without sending another get to the server.
The question is, can I access DT data array, and can I edit it?
How is it done if is possible?
EDIT: I need to feed the table the full bean array as it initially took from the server, same format. So individual row/cell add/edit and client-side building functions are not suitable in my case, unless I manually cicle all objects.
SOLUTION
Use the code below:
// Retrieve data
var data = table.ajax.json();
// Modify data
$.each(data.data, function(){
this[0] = 'John Smith';
});
// Clear table
table.clear();
// Add updated data
table.rows.add(data.data);
// Redraw table
table.draw();
DEMO
See this jsFiddle for code and demonstration.

Using Jquery methods on Data Returned from Ajax, with out printing out the data

So I have a rather unique situation. I am using JQuery to gather some data based on two date ranges, what is returned as a response in the $data variable (I am using Ajax) I have set, is a html table.
Now I don't want the user to ever see this table, I want to use This jquery plugin to download the CSV file of that table. The question is, if the table sits inside of a $data and can be seen via the network tab in Chrom Dev Tools, under Response, is it possible to be manipulated with Jquery?
In our inhouse framework, we do the following to get Ajax Data:
// The following belongs to a JS class method.
data = {
startDate : $('.startDate').val(),
endDate : $('.endDate').val()
}
CT.postSynch('report/payRollReport/downloadPayRoleReport', {data : data}, function(data){
console.log(data);
});
We pass a data object to our Ajax wrapper, call a controller with an action (in this case downloadPayRoleReport translates to ajaxDownloadPayRoleReport()) which in turn returns an HTML table, which I can view via console.log(data)
I want to use the above linked plugin on data to then turn this html table into a csv and instant download.
Question is, can this be done?
You can create a jQuery object from the table. Then you can do anything to the jQuery object just like you could if it were actually on the DOM. You can always put the table on the DOM as well off screen, but I think any chance you have to not touch the DOM you should take it.
var myTable = $(data);
myTable.mySpecialTableMethodToExportToCSV();

How to re-render the page after a database add call without refreshing?

Hi I am using a form which takes input of some data and when I press submit an Ajax Post request goes to the server which then saves the data in the database and then data only gets updated on the ejs Page when I press refresh.
I want to know is there any way I can make any call through either Jquery or JavaScript that on the success of AJAX POST re renders the ejs page and page is again functional without refreshing?
I tried to use the below code to re load the page what it does is; it works, reloads the data but that data is not accessible or its values are not usable until I refresh
The code I used
$('body').load('views/test.ejs', function () {
$(this).fadeIn(5000);
});
My rendering function looks like this;
function renderList(res, list) {
res.render('admin', {
jsonList: list, // JSON of data generated from DB
listId: req.session.user.listID, //global session
access: req.session.user.Access, //global session
products: req.session.user.Products, //global session
user: req.session.user.FirstName || req.session.LastName
});
}
I have a tabbable menu of bootstrap in which I am passing the IDs of the data from Databases and using those tabbable menu to display corresponding data of that item. So I am not getting IDs when I just use the Load function. only location.reload() works for me but its not a good way to do it.
jQuery .ajax() and .post() have success callback functions that you can use to update the page with your new data. Try looking at this answer of mine for an example.

Categories