sapui5 JSON model and display in xml - javascript

I need help with setting JSON model into my main model. I have data stored in "http://localhost:9041/main-app-web/MyServiceName.svc/GetSurname?id=1&name='matt'&$format=json"
Now i want to set it into model, i'm trying
var oModelJs = new sap.ui.model.json.JSONModel("/main-app-web/MyServiceName.svc/GetSurname?id=1&name='matt'&$format=json");
this.getView().setModel(oModelJs, "model");
but it is giving me oData ={} ,
empty oData in debugger. How could i do that and then display my data eg. in table in xml?
Parameters stored in my json:
Id: "223",
MeterNumber: "1354-65498121"
Ty guys

this.getView().setModel(oModelJs, "model");
The above line of code is not needed.
Next yo have to get the table ID and set the model to the table.
this.getView().byId("tableId").setModel(oModelJs);

The way i solved this problem was adding correct items into <Table items="{/d/results}"> and in cells <Text text="{id}" /> Ty for ur response santosh.

Related

Data from a WebSocket into a Table with JavaScript

my Script is reading Data given from a WebSocket and my goal is, to save the Data from the Websocket in a Table (HTML). This is what my Function looks like, as you can see im reading the Data from an Object, and im trying to display each Object in my HTML Table.
function websocketPush(item){
let t_item = {}
for ( let key in properties){
t_item[key] = resolve(properties[key],item);
}
t_item["id"] = id;
id++;
//data.push(t_item);
//data = data.slice(-30);
table.addData([t_item],true);
}
But instead of logging each item in the Table, its just logging 1 by 1 and keeps resetting the old ones.
So basically I want all the logged filed in the table and not just the newest one. I think my problem is the "id++" but I just dont know any better...
Any Help is appreciated! Thanks in advance!

DHTMLX Grid Pulling Additional Data

I am trying to build an app for users to submit their work times in but am having trouble with pulling additional data into the grid.
Eg: If a user were to type in there employee code of 0000 into the Employee Code Column the Employee Name Field would need to update to read "John Doe" All this data is stored in databases on the back end and I have been able to access it on refresh eg. If the page is reloaded after the new row has been created and the data is present it will pull the correct data in, but i do not want them to have to refresh the page to do this. How can I pull in the extra data after the cell has been updated.
The Grid is created on the page with JavaScript as follows:
timesheetGrid.setColumnIds("Column Names, Column Names");
timesheetGrid.setImagePath("codebase/imgs/"); //set the image path for the grids icons
timesheetGrid.setInitWidths("70,100,100,100,70,100,150,100,70,70,100,70,70,*,*"); //sets the initial widths of columns
timesheetGrid.setColAlign("center,center,center,center,center,center,center,center,center,center,center,center,center,left,left"); //sets the alignment of columns
timesheetGrid.setColTypes("edn,ro,dhxCalendar,ro,edn,ro,ed,ro,ro,ro,ed,edn,ch,txt,ro"); //sets the types of columns
timesheetGrid.setColSorting("str,str,date,date,str,str,str,str,str,str,str,str,str,str,str"); //sets the sorting types of columns
timesheetGrid.setDateFormat("%Y-%m-%d"); //Set the Date Format to be used in the Grid
timesheetGrid.attachHeader("#text_filter,#text_filter,#text_filter,,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,#text_filter,,,");
timesheetGrid.setColumnHidden(3,true);
timesheetGrid.enableEditEvents(true,false,true);
timesheetGrid.init();
//timesheetGrid.makeFilter("WeekEnding",0); //TODO: Add Filter For Week Ending
//this.lockRow(id, true); //Make Specific Row Read Only TODO: Non Active Week Rows Read Only
timesheetGrid.load("data/timesheets.php");
var dpg = new dataProcessor("data/timesheets.php");
dpg.enableDataNames(true); // will use names instead of indexes
dpg.init(timesheetGrid);
PHP is used to pull data from the correct avenues
require("../codebase/connector/grid_connector.php");//adds the connector engine
$conn = new GridConnector($res,"MySQL"); //initializes the connector object
if ($conn->is_select_mode()) {//code for loading data
SQL Code is HERE
}else { //code for other operations - i.e. update/insert/delete
OTHER SQL CODE IS HERE
}
As the Data is sensitive I cannot display any of it sorry for any inconvenience.
Any Help would be much appreciated.
If the data you're providing is XML you can attach an event to your grid and call this grid.updateFromXML("data/timesheets.php");
This will parse and paint the whole grid information
If you're looking to update just the row you updated you can send via GET the id of the row and it will only parse and paint the row you're sending
grid.updateFromXML("data/timesheets.php?for=" + row_id));
Full Code would be something like this:
dpg.defineAction ("update", myUpdate);
function myUpdate(tag){
timesheetGrid.updateFromXML("data/timesheets.php?for="+tag.getAttribute("sid"));
return true;
}
If the data you're retrieving is not XML formatted, I'm afraid you would need to update the values from the row manually via the same event.

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.

Displaying data in dojo grid

I have a hash map dataFields = {"element1":1,"element2":2,"element3":3} and I am trying to display the data in a dojo grid. However, when I set up my data store like:
var data = { identifier: "element1",
items: []
};
payload = JSON.stringify(dataFields);
data.items.push(payload);
var store = new dojo.data.ItemFileWriteStore({data: data});
the grid does not display anything. Now I know that the grid is set up correctly because when I pass in a JSON file to test my grid it displays the contents of the file without any errors.
I should mention that dataFields is a response of a GET and the entire response is not useful to me that is why I extract the useful fields and put them in a hash map and try to display them. I feel like I am missing something essential here regarding how the data stores work. So I guess, the right question to ask is, how would I setup my data store so that the grid displays my hash map? Or is there a better way to do it than using a hash map?
So it turns out that I did not need to 'stringify' the hash map. I just put in data.items.push(datafields) and it worked. The only reason I was doing it because I thought if I make it a string then it would imitate a JSON object. Turns out I was wrong because JSON text is kind of a hash map.

Send JSON Object to Rails

Hi I'm new to rails so please bear with me :) I want to send JSON object to rails and save it to database. basically I have a data entered by the user then I have a javascript function thats retrieves the data and convert it into JSON object. What i want is to sent the JSON object maybe through ajax to rails and save it to the database.Can anyone give me any idea how to do it. thnx
function save(){
----(some codes)
notesArray.push({ Index: i, Title: title.val(), Content: content.val()});
// json encode it
var jsonStr = JSON.stringify(notesArray);
//want to add code here to send to rails
}
If you're using jQuery, it's very easy to do this using $.post():
$.post('/some/page/here', {notes: jsonStr});
As to "handle the JSON object in the controllers" you can use parsed_params = CGI.parse(params[:_json]) ,then you can get what you what througt parsed_params[key1][key2]

Categories