Author Topic: datamodel getData - What's the JSON format needed?  (Read 3088 times)

angelahlp

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 51
    • View Profile
datamodel getData - What's the JSON format needed?
« on: June 04, 2014, 11:15:35 am »
Ok - I've tried just about every way I can think of but can't figure this out. I am trying to set the dataModel using getdata with a call to a ColdFusion CFC as follows:
dataModel: {
            dataType: "JSONP", <--- I've tried JSON and JSONP
            location: "remote",
            recIndx: "contactid",
         url: '/cfc/Contact.cfc?method=getContactsMatrix',
            getData: function (response) {
                return { data: response };
            }
        },

The value that is returned from getContactsMatrix is as follows (have tried many different formats, but it seems like this format should work:

[{"work_phone":"(xxx) 293-4628","businessname":"Testing","stateabbr":"OH","contactid":53330,"contacttype":"Individual"},{"work_phone":"(xxx) 681-6702","businessname":"Testing 2","stateabbr":"MO","contactid":53364,"contacttype":"Individual"}]

I've tried the above with and without the enclosing []

My ColModel definition is:
 colModel: [
         { title: "Contact ID", dataType: "integer", editable: false, dataIndx: "contactid", hidden: true },
         { title: "Contact Type", width: 160, dataIndx: 'contacttype',
            editor: {
               type: 'select'
            },
            filter: { type: 'select',
               options: '',
               condition: 'equal',
               listeners: [{ change: function (evt, ui) {
                  filter("contacttype", $(this).val());
                  }
               }]
            }
         },
         { title: "State", width: 50, dataIndx: 'stateabbr',
            editor: {
               type: 'select'
            },
            filter: { type: 'select',
               options: '',
               condition: 'equal',
               listeners: [{ change: function (evt, ui) {
                  filter("stateabbr", $(this).val());
                  }
               }]
            }
         },
         { title: "Full Name", width: 200, dataType: "string", dataIndx: "fullname",
            filter: { type: 'textbox', condition: 'contain',
               listeners: [{ change: function (evt, ui) {
                  filter("fullname", $(this).val());
               }
               }]
            }
         },
         { title: "Work Phone", width: 200, dataType: "string", dataIndx: "work_phone",
            filter: { type: 'textbox', condition: 'contain',
               listeners: [{ change: function (evt, ui) {
                  filter("work_phone", $(this).val());
               }
               }]
            }
         },   
            { title: "", editable: false, minWidth: 140, sortable: false, render: function (ui) {
                return "<button type='button' class='edit_btn'>Edit</button>\
                    <button type='button' class='delete_btn'>Delete</button>";
            }
            }
        ],

Can someone please tell me what I'm doing wrong? I get a blank grid ... I MUST include the dataIndex in the ColModel as I'm using that other places to reference the columns...

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6309
    • View Profile
Re: datamodel getData - What's the JSON format needed?
« Reply #1 on: June 04, 2014, 11:34:31 am »
your dataModel.dataType should be 'JSON'

your data is valid JSON but you need to ensure that you are getting same data in getData callback. Put an alert or breakpoint in getData callback and check the value of response.

Also check for any error in the browser console.