jQuery UI Widgets › Forums › Grid › Show row data if first rows datafield is undefined
This topic contains 4 replies, has 2 voices, and was last updated by RareDevil 10 years ago.
-
Author
-
I have a problem with the grid if I use data like in the sample below the rows with the datafield for Data2 and Data5 don’t show any data, is there a workaround or something that can make the rows show data even if the first or couple of first rows don’t have there datafield defined?
Sample code:
$(document).ready(function () { var data = [{"Id":1,"Data1":"Somedata","Data3":"Somedata","Data4":"Somedata"},{"Id":2,"Data1":"Somedata","Data2":"Somedata","Data3":"Somedata","Data4":"Somedata","Data5":"Somedata"},{"Id":3,"Data1":"Somedata","Data2":"Somedata","Data3":"Somedata","Data4":"Somedata","Data5":"Somedata"},{"Id":4,"Data1":"Somedata","Data2":"Somedata","Data3":"Somedata","Data4":"Somedata","Data5":"Somedata"},{"Id":5,"Data1":"Somedata","Data2":"Somedata","Data3":"Somedata","Data4":"Somedata","Data5":"Somedata"}]; var source = { datatype: "json", datafields: [ { name: 'Data1' }, { name: 'Data2' }, { name: 'Data3' }, { name: 'Data4' }, { name: 'Data5' } ], localdata: data }; var dataAdapter = new $.jqx.dataAdapter(source); $("#jqxgrid").jqxGrid({ width: 850, source: dataAdapter, pageable: true, autoheight: true, sortable: true, altrows: true, enabletooltips: true, editable: true, selectionmode: 'multiplecellsadvanced', columns: [ { text: 'Data 1', datafield: 'Data1' }, { text: 'Data 2', datafield: 'Data2' }, { text: 'Data 3', datafield: 'Data3' }, { text: 'Data 4', datafield: 'Data4' }, { text: 'Data 5', datafield: 'Data5' } ] }); });
Hello RareDevil,
We tested your example with jQWidgets version 3.6.0 and it works as expected – only the first cells of “Data2” and “Data5” are empty. Please make sure you are using version 3.6.0, too.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Well I have now tried the same code my self and found out that i cant show the error in that way, since it happens when i use a ajax call to get the data.
A example of the javascript code:$(document).ready(function () { $.ajax({ url: "http://localhost/GetData", dataType: 'json', beforeSend: function () { //$("jqxgrid").html(''); }, error: function (json, textStatus, errorThrown) { console.log(' Error :' + errorThrown); }, success: function (data) { // initailize grid var gridData = data; var gridSource = { localdata: gridData, datatype: 'json', id: 'Id' }; var gridDataAdapter = new $.jqx.dataAdapter(gridSource); $("#jqxgrid").jqxGrid( { width: '100%', height: "100%", source: gridDataAdapter, pageable: false, filterable: true, sortable: true, showfilterrow: true, columnsresize: true, enabletooltips: true, editable: false, showtoolbar: false, groupable: true, showgroupsheader: false, selectionmode: 'multiplecellsadvanced', columns: [{ text: 'Data 1', datafield: 'Data1', width: 250 }, { text: 'Data 2', datafield: 'Data2', width: 250 }, { text: 'Data 3', datafield: 'Data3', width: 250 }, { text: 'Data 4', datafield: 'Data4', width: 250 }] }); } }); });
The data will be some what the same where the first row are missing one or two data fields.
Also right now im using 3.5.0 but i have tested it with 3.6.0 and there it did not work either.Hi RareDevil,
In your second example you have not defined the grid source datafields. Please, define them and the issue should be gone.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks that worked, abit more code but since it made it work its better then it dont work
-
AuthorPosts
You must be logged in to reply to this topic.