Can I edit the datasource programatically with JavaScript? - javascript

I have a grid that pulls data via ajax into the datasource.
Once that data is pulled, I want to modify a bunch at once through JS. I have tried modifying the datasource directly via something like:
gridDataSource._data[j].SomeProperty = 'true;
But that does not reflect in the grid itself. Is there any way to do that? I would also prefer the grid gets marked dirty so I could use the update command to send the data back to the server. Is this possible? Please let me know if I need to clear anything up.

I think you need to use the set method - like this:
var data = $("#grid").data("kendoGrid").dataSource.data();
data[i].set("SomeProperty", true);

After you modify the datasource, you need to refresh.
$('#myGrid').data('kendoGrid').refresh();

Related

Dynamic NAV Control Add-in exchange data

Im solving how to exchange data between JS control add-in and NAV.
Now, when I want to get data from JS control add-in to NAV. I call from NAV, JS method and in JS method I call method in NAV. See example below.
Is there some easy way e.g. return values on first call from NAV?
Because I need data from JS in one method.
Thank you for your help.
C/AL Code
d::someMethod()
//I need to work with data from JS here
CurrPage.d.getDataFromJS();
d::receiveDataFromJS(data: Variant)
//here I receive data from JS
JS
function getDataFromJS() {
var result = 'bla bla';
Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('receiveDataFromJS', [result]);
}
You can return data from your addin via events. Just define the event in your dll and reinclude your addin, it should then be visible in the C/AL. To trigger the event on JavaScript side use Microsoft.Dynamics.NAV.InvokeExtensibilityMethod('eventName', [parameters]);
The parameters you parse here can then be used to parse your data to the NAV-side. I hope this helps you

Load data with AJAX only if it has not already been loaded?

I need to load data for my JavaScript app to use. I would like to load the following:
userlist JSON
milestones JSON
Tags JSON
user ACL permissions JSON
These 4 items of data from the server as JSON should be loaded using AJAX but only loaded once.
So I need code that will check to see if the data is loaded already and if it is, use it. If it is not loaded yet, it would make an AJAX request and load the data, and then use it.
I have multiple JavaScript files which need access to this data so I want to make sure that any of them can access it, and whichever once calls for it first will load it using AJAX and make it available for the other scripts to call it without making multiple repeat AJAX requests.
How could I go about this using JavaScript and jQuery?
A basic example would be super appreciated and useful. Thank you
If any of these are not set, load them using AJAX. After loading with AJAX, set these vars for the next caller to access them without a new AJAX request being made...
var userList = userJsonData;
var milestoneList = milestoneJsonData;
var tagList = tagJsonData;
var useAclPermissions = useAclPermissionsJsonData;
Just store the data in a global javascript variable, which is set to null, when your page loads. The first script which loads the data, stores it in the variable, all the other scripts try to access the content of the variable, and if not set, load it:
var milestoneData = null;
function getMilestoneData() {
if (milestoneData === null) {
//make the ajax request, and populate milestoneData variable
} else return milestoneData;
}
According to can i use you can check out localstorage aka webstorage. If you can use it, it might solve your issues. There is a jQuery plugin available. jstorage is an alternative, and has a really simple example at the bottom of the page. Hope this helps.

How to Update Model in AngularJS when Ajax used Long Polling?

How to update the model when i used ajax long polling technique?
At first i will load the default list
Example:
- id1
- id2
- id3
Then in my background process, i setup a ajax long polling that will run every 5seconds interval.
When the ajax receive an update it will update the display in angularjs accordingly without refreshing page.
So from the example below, when i receive changes, it should output something like this:
Example:
- id1
- im New Here..
- id3
Is that possible using this technique?.. without using any websocket or nodejs...
Thanks
Yes it's possible.
I assume you want to do a GET request every 5 seconds so not really keeping your connection open constantly.
If you place the request method inside your scope you could do something like this:
$scope.ids = ['id1','id2','id'3]; //by initial request.
postFunction() {
//Request here
var newData = request.data;
$scope.ids.push(newData);
}
Since Angular modals use 2way databinding your html gets updated instantly.

How can I refresh the page after an ajax call but passing parameters as well? I.e. not full refresh

I am using ajax from JQuery. I am doing in a page that I see the results of a POST/GET having provided specific parameters as filters to the server.
Assume I have provided parameters a&b&c to the user so that I see in the page the subset of the data that these parameters hold true.
In a specific case I do an ajax call to pass a value to the server that modifies this set that I am seeing.
What I need is a way to do a refresh of the page but that will only display the new version of the current subset of data I.e. somehow refreshing passing back to the server a&b&c
Right now I am doing: window.location.reload(true); which reloads all the data and it is time-consuming to re-apply the filters manually.
How can I solve this?
Essentially what I need is not full refresh?
If you are using Ajax from jQuery and want to do a partial reload but have chosen window.location.reload, then you are doing it wrong.
Use the format
$("#someDiv").load("someUrl?a=x&b=y")
or
$.get("someUrl?a=x&b=y",function(data) { $("#someDiv").html(data)});
for example this code in the head where .parameters could be checkboxes
$(function() {
$(".parameters").on("click",function() {
var url = "someUrl.php?"+$("#myForm").serialize();
$.get(url,function(data) {
$("#someContainer").html(data);
});
});
});
You would have to return something from the server which will contain th einformation needed to update
And then update the content based on the returned data.

Passing javascript variable to partial via render_javascript

I receive a google ID from an Ajax call and then want to use that ID to update a button on my view.
Here is the code in new.js.erb, which is linked to a new.html.erb.
Problem is, I don't know how to pass the variable's content. Restaurant is a json. The alert returns the correct ID and when I search my db on the terminal with the returned google id I find the restaurant.
Here is the code:
alert(restaurant["google_id"]);
var google_id = restaurant["google_id"];
$("#rating_bar").html("<%= escape_javascript(render 'reviews/buttons/full_profile_rate_restaurant', :google_id => "+google_id+".html_safe) %>");
What happens is that the variable being passed is the string "google_id" instead of the combination of letters and numbers that is the google ID. I've tried multiple approaches, this is just one of many wrong one - I think this question is pretty easy for anyone who knows their JS really well.
It is not possible to pass a JS variable to the ruby partial.
As Ryan Bigg explained for the same type of problem here, its not possible to send the variable while rendering that partial. We need to work out some thing else. Even i also had the same issue once.
Alternatively,
if that is google_id is only a variable to display in the partial, then update those divs manually after rendering that partial.
like
$("#rating_bar").html("<%= escape_javascript(render 'reviews/buttons/full_profile_rate_restaurant', :google_id => "sample_id") %>");
// Now update the required elements
$("#what-ever-ids").text(google_id);
or just create some other action in that controller, and call send an ajax request to that action, and there you will have this js variable, and in that js.erb file render the same partial which you actually want to update with the google_id variable.

Categories

Resources