{"action":"created","issue":{"url":"https://api.github.com/repos/openpsa/grid.js/issues/46","labels_url":"https://api.github.com/repos/openpsa/grid.js/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/openpsa/grid.js/issues/46/comments","events_url":"https://api.github.com/repos/openpsa/grid.js/issues/46/events","html_url":"https://github.com/openpsa/grid.js/issues/46","id":54167762,"number":46,"title":"datatype autodetection","user":{"login":"flack","id":425166,"avatar_url":"https://avatars.githubusercontent.com/u/425166?v=3","gravatar_id":"","url":"https://api.github.com/users/flack","html_url":"https://github.com/flack","followers_url":"https://api.github.com/users/flack/followers","following_url":"https://api.github.com/users/flack/following{/other_user}","gists_url":"https://api.github.com/users/flack/gists{/gist_id}","starred_url":"https://api.github.com/users/flack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flack/subscriptions","organizations_url":"https://api.github.com/users/flack/orgs","repos_url":"https://api.github.com/users/flack/repos","events_url":"https://api.github.com/users/flack/events{/privacy}","received_events_url":"https://api.github.com/users/flack/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/openpsa/grid.js/milestones/1","labels_url":"https://api.github.com/repos/openpsa/grid.js/milestones/1/labels","id":931979,"number":1,"title":"1.0","description":"Lets merge everything together and try and make a proper release.","creator":{"login":"meh-uk","id":398750,"avatar_url":"https://avatars.githubusercontent.com/u/398750?v=3","gravatar_id":"","url":"https://api.github.com/users/meh-uk","html_url":"https://github.com/meh-uk","followers_url":"https://api.github.com/users/meh-uk/followers","following_url":"https://api.github.com/users/meh-uk/following{/other_user}","gists_url":"https://api.github.com/users/meh-uk/gists{/gist_id}","starred_url":"https://api.github.com/users/meh-uk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/meh-uk/subscriptions","organizations_url":"https://api.github.com/users/meh-uk/orgs","repos_url":"https://api.github.com/users/meh-uk/repos","events_url":"https://api.github.com/users/meh-uk/events{/privacy}","received_events_url":"https://api.github.com/users/meh-uk/received_events","type":"User","site_admin":false},"open_issues":9,"closed_issues":2,"state":"open","created_at":"2015-01-12T18:25:42Z","updated_at":"2015-01-14T08:34:23Z","due_on":null,"closed_at":null},"comments":26,"created_at":"2015-01-13T09:29:46Z","updated_at":"2015-01-14T10:54:39Z","closed_at":null,"body":"Based on @bouks implementation and the feedback from @OlegKi, here's a proposal for a modified autodetection algorithm (written as pseudocode for better readability):\r\n\r\n```javascript\r\nif (grid.datatype !== 'auto')\r\n{\r\n    grid.url = \"\" + grid.url //Cast URL to string\r\n    //normal jqGrid setup as it was before\r\n}\r\nelse\r\n{\r\n    if (grid.data !== null)\r\n    {\r\n        grid.datatype = 'local';\r\n    }\r\n    else if (grid.url !== null)\r\n    {\r\n        detected_datatype = do_ajax_request_and_detect_datatype_with_jquery();\r\n        if (detected_datatype === null)\r\n        {\r\n            throw 'datatype could not be detected. Please specify it manually';\r\n        }\r\n        if (    grid.loadonce === true\r\n            && (detected_datatype === 'xml' || detected_datatype === 'json'))\r\n        {\r\n            grid.datatype = 'local'\r\n        }\r\n        else\r\n        {\r\n            grid.datatype = detected_datatype;\r\n        }\r\n    }\r\n    else\r\n    {\r\n        grid.datatype = 'clientSide';\r\n    }\r\n}\r\n```\r\n\r\nThe autodetection should only run once, when the grid is initially constructed.\r\n\r\nFrom the user's point of view, the behaviour would be like this:\r\n\r\nUsing local data:\r\n\r\n```javascript\r\n$('#list').jqGrid({\r\n    colModel: [ name: \"colName\"],\r\n    data: some_data\r\n});\r\n```\r\n\r\nusing remote data:\r\n\r\n```javascript\r\n$('#list').jqGrid({\r\n    colModel: [ name: \"colName\"],\r\n    url: \"/backend.php\"\r\n});\r\n```\r\n\r\nusing nothing at all:\r\n\r\n```javascript\r\n$('#list').jqGrid({\r\n    colModel: [ name: \"colName\"],\r\n}).jqGrid('setGridParam', {data: some_data});\r\n```\r\n\r\nusing remote data from the current URL:\r\n\r\n```javascript\r\n$('#list').jqGrid({\r\n    colModel: [ name: \"colName\"],\r\n    url: \"\"\r\n});\r\n```"},"comment":{"url":"https://api.github.com/repos/openpsa/grid.js/issues/comments/69899746","html_url":"https://github.com/openpsa/grid.js/issues/46#issuecomment-69899746","issue_url":"https://api.github.com/repos/openpsa/grid.js/issues/46","id":69899746,"user":{"login":"flack","id":425166,"avatar_url":"https://avatars.githubusercontent.com/u/425166?v=3","gravatar_id":"","url":"https://api.github.com/users/flack","html_url":"https://github.com/flack","followers_url":"https://api.github.com/users/flack/followers","following_url":"https://api.github.com/users/flack/following{/other_user}","gists_url":"https://api.github.com/users/flack/gists{/gist_id}","starred_url":"https://api.github.com/users/flack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flack/subscriptions","organizations_url":"https://api.github.com/users/flack/orgs","repos_url":"https://api.github.com/users/flack/repos","events_url":"https://api.github.com/users/flack/events{/privacy}","received_events_url":"https://api.github.com/users/flack/received_events","type":"User","site_admin":false},"created_at":"2015-01-14T10:54:39Z","updated_at":"2015-01-14T10:54:39Z","body":"@OlegKi Yes, that is what i had in mind. The autodetection should only run once during the inital setup of the grid. I noticed that I forgot to write this in the original ticket, but I've updated the description now.\r\n\r\nIt should be possible to combine your idea with @bouks autodetection of remote data. i.e. if `data` is not set initially, we can send the request and then set `json` or `xml` as appropriate"}}