Alpha Video Training
Results 1 to 4 of 4

Thread: JSON Field Display UX List Control MySQL

  1. #1
    Member MichaelCarroll's Avatar
    Real Name
    Michael Carroll
    Join Date
    Feb 2008
    Posts
    467

    Default JSON Field Display UX List Control MySQL

    I have a simple UX Control where I want to display a list of projects and contact details. I would like the contact details to be a JSON object so that I can save it to a MySQL table.

    I have created a List Control named Projects

    I have created a spreadsheet control

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,537

    Default Re: JSON Field Display UX List Control MySQL

    I think there's a question in here... but not sure.

    1. You want to save the JSON definition, in a MySQL field, for feeding a Spreadsheet control.
    2. You want to get that JSON, fill it with Contact Details data, and send it on to the SpreadSheet Control

    So... you've got a List Control for Projects. You click on a Project and then perform an Ajax Callback to get the JSON definition, fill it with data, and return it do the Spreadsheet control.

    Any of this right?

  3. #3
    Member MichaelCarroll's Avatar
    Real Name
    Michael Carroll
    Join Date
    Feb 2008
    Posts
    467

    Default Re: JSON Field Display UX List Control MySQL

    Hi David and Group

    I thought I was still editing that post... Ha...

    So to finish... I want to effectively:
    1. Read and write JSON from a spreadsheet control to a JSON feild in MySQL
    2. Be able to setup a complex spreadsheet control to do complex parameters for an inventory part.

    Ok I get what I need to change to populate the spreadsheet. My resultset is toString() not toJson()
    --- See my notes below ---

    BUT HOW do I now submit, when the spreadsheet columns are bound
    to individual fields?


    Ok so I am just using a simple table with two fields:

    Contacts.
    --- Name as a VarChar(255)
    --- Details as a TEXT or JSON

    The "Smith Family" in Name field and then the JSON statement in the Details:

    Code:
    {"Name" : "Bob Smith", "Phone" : "123-123-1234", "Type" : "POC"}, 
    {"Name" : "Linda Smith", "Phone" : "123-123-1234", "Type" : ""},
    {"Name" : "Glenda Amazing", "Phone" : "123-123-1234", "Type" : "Designer"}
    The example from the Alpha Release Notes reads this from standard SQL fields in a result set, "Name", "Phone", "Type".
    In figuring out how this works I am looking at how the spreadsheet data is populated from a
    SQL query and its result set.

    ====== OK here is the results set ======

    Button to populate
    Code:
    {dialog.object}.ajaxCallback('','','xb','','',{deviceOfflineFunction: function() {   }});
    ====== From my XB Function ======

    Code:
    cn.open("::Name::Shade")
    cn.Execute("select * from contacts)
    dim json as c 
    json = cn.ResultSet.toJson()
    ====== This is the ResultSet.toJson =========
    ====== SO FOR A JSON Field I use ResultSet.toString() that was easy! ======
    Code:
    [
    {"Name": "Bob Smith", "Phone": "123-123-1234", Type: "POC"}, 
    {"Name": "Linda Smith", "Phone": "123-123-1234", Type: ""},
    {"Name": "Glenda Amazing", "Phone": "123-123-1234", Type: "Designer"}
    ]
    ====== then the stritran() ========
    json = stritran(json,crlf()," ") Take the carriage return after and before the [ ] brackets and comma
    seperating the lines so that we have one string.

    Result
    Code:
    [ {"Name": "Bob Smith", "Phone": "123-123-1234", Type: "POC"},{"Name": "Linda Smith", "Phone": "123-123-1234", Type: ""},{"Name": "Glenda Amazing", "Phone": "123-123-1234", Type: "Designer"} ]
    ====== then add var _d = infront of the json string and semicolon and cariage return line feed after. ====

    Code:
    js = "var _d = " + json + ";" + crlf()
    Result
    Code:
    var _d = [ {"Name": "Bob Smith", "Phone": "123-123-1234", Type: "POC"},{"Name": "Linda Smith", "Phone": "123-123-1234", Type: ""},{"Name": "Glenda Amazing", "Phone": "123-123-1234", Type: "Designer"} ];
    ====== then create the javascript to execute =========

    Code:
    js = "var _d = " + json + ";" + crlf()
    js = js + "var _data = JSON.stringify(_d); {dialog.object}.setValue('ss1',_data);
    Result
    Code:
    var _d = [ {"Name": "Bob Smith", "Phone": "123-123-1234", Type: "POC"},{"Name": "Linda Smith", "Phone": "123-123-1234", Type: ""},{"Name": "Glenda Amazing", "Phone": "123-123-1234", Type: "Designer"} ];
    var _data = JSON.stringify(_d);
    {dialog.object}.setValue('ss1',_data);  //ss1 is the spreadsheet control
    It works!!!

    But now how to submit changes....?

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,537

    Default Re: JSON Field Display UX List Control MySQL

    You don't really need to do some of what you're doing... and I prefer to call a Javascript function for some of it as well. It seems less messy on the XBasic side.

    This will send the JSON to the client and fire off a Javascript function name loadSSDemoData. The only real difference is that you don't have to stringify the JSON.

    Code:
    rs = cn.ResultSet
    
    jsonData = rs.toJSON();
    
    dim returnData as c
    returnData = "var demoData = " + jsonData + "loadSSDemoData(demoData);"
    
    getssDemoData = returnData
    The Javascript function is...

    Code:
    function loadSSDemoData(demoData){
    
    	var obj = {dialog.object}.getControl('ss1');
    	obj.setColumnsAndPopulate(demoData);
    
    }
    When you submit your UX, all the data from the SpreadSheetControl will be in e.dataSubmitted.SS1

    You'll then parse that JSON into whatever you need to perform your updates. The spreadsheet columns aren't really bound to individual fields. Their data came from tables fields, parsed into JSON and fed into the control... but there's no field binding.

    It's... Select --> parse --> populate --> submit --> parse --> update.

Similar Threads

  1. display logical field as checkbox in a list control
    By frankbicknell in forum Mobile & Browser Applications
    Replies: 52
    Last Post: 04-04-2018, 01:35 PM
  2. Data-bound image will not display in a list control
    By spoweroz in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 05-08-2017, 09:54 PM
  3. How to populate a List from a JSON formatted field?
    By WindForce in forum Mobile & Browser Applications
    Replies: 7
    Last Post: 04-03-2017, 02:52 AM
  4. How to display text messages in a list control?
    By Gatorfan in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 08-29-2015, 04:14 PM
  5. Adding Records - List Control with contcat mysql field
    By joegrun4 in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 11-18-2014, 07:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •