Title: [SOLVED] Combogrid cannot read property 'idField' of null
Post by: acreonte82 on February 21, 2017, 03:00:13 PM
Hello to all, i've this combogrid: $('#dna_position').combogrid({ panelWidth:750, url: 'controller/search_stock_position.php', idField:'warehouse_number', textField:'warehouse_number', mode:'remote', fitColumns:true, columns:[[ {field:'warehouse_number',title:'Fridge number',width:250}, {field:'type_of_instrument',title:'Fridge',width:250}, {field:'placing',title:'Place',width:250}, ]] }); This combo in used to load data in a form and the form load the data in this way: $('#dati_dna').form('load', data); The problem is: if i retrive data from server and no data for the combogrid i've this error: Uncaught TypeError: Cannot read property 'warehouse_number' of null So the question is: how i can solve it? there is a pre-check before to prevent this? Thanks for the help
Title: Re: Combogrid cannot read property 'idField' of null
Post by: jarry on February 21, 2017, 07:58:28 PM
How do you declare the <form> and combogrid component. Please show an example to demonstrate your issue.
Title: Re: Combogrid cannot read property 'idField' of null
Post by: acreonte82 on February 22, 2017, 01:27:18 AM
Hi, thanks for the support! This is the html code of the form : <form id="search_samplePatient"> <div> <label>Search the patient using the protocol number and/or sample number and/or the biological sample type<br/><br/> <input id="cg_ricerca_paziente" style="width:250px" tabindex="10" class="easyui-validatebox" required="true"></input> </label> </div> <div> <input type="button" name="Send" value="Search" tabindex="20" onclick="javascript: loadDataQtaSample($('#tt_modifica_qta_sample').tabs('getTabIndex',$('#tt_modifica_qta_sample').tabs('getSelected')));" tabindex="20"> </div> </form> <div class="easyui-tabs" id="tt_modifica_qta_sample" > <!-- many tabs defined here --> <div title="DNA" style="padding:10px;" > <form id="dati_dna" method="post"> <table> <tr><input type="hidden" name="dati_extra" value=""> <td>DNA quantity:</td> <td><input name="dna_num_vials_volume" type="text"></input></td> </tr> <tr> <td>DNA position:</td> <td><input id="dna_position" name="dna_position" style="width:150px"></input></td> </tr> <tr> <td>DNA sampling date:</td> <td><input name="sampling_date_dna_position" id="sampling_date_dna_position" class="easyui-datebox" type="text"></input></td> </tr> <tr> <td colspan="2"> <input type="button" name="Send" value="Modify" onclick="javascript: submitFormQtaSample(this.form);" > </td> </tr> </table> </form> </div> </div>
And this is my javascript code to load data in the form: <script type="text/javascript" language="javascript"> function myformatter(date){ var y = date.getFullYear(); var m = date.getMonth()+1; var d = date.getDate(); return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d); } function getParametersQtaSample(dati_ricerca,id_tab){ return 'controller/type_modifica_qta_campione_biologico.php?tab='+ id_tab +'&dati_ricerca='+ dati_ricerca; } function loadDataQtaSample(id_tab){ var data=''; var g = $('#cg_ricerca_paziente').combogrid('grid'); // get datagrid object var r = g.datagrid('getSelected'); // get the selected row switch(id_tab){ case 1: $('#sampling_date_dna_position').datebox({ formatter:myformatter, parser:myparser }); $('#dna_position').combogrid({ panelWidth:750, url: 'controller/search_stock_position.php', idField:'warehouse_number', textField:'warehouse_number', mode:'remote', fitColumns:true, columns:[[ {field:'warehouse_number',title:'Fridge number',width:250}, {field:'type_of_instrument',title:'Fridge',width:250}, {field:'placing',title:'Place',width:250}, ]] }); data=getParametersQtaSample(r.dati_ricerca,id_tab); $('#dati_dna').form('load', data); break; } } </script>
the getParametersQtaSample function call a php script that retrive the data after a specific query and return all by json array. The json array has the key value egual the name value defined in the input control form. The combogrid is preload when the webpage is loaded, then when i call $('#dati_dna').form('load', data) the combogrid select the right value defined in the json array. The problem is when the json array return null value, in the console of Chrome I've this error: Uncaught TypeError: Cannot read property 'warehouse_number' of null So my question is how i can manage this kind of situation?
Title: Re: Combogrid cannot read property 'idField' of null
Post by: jarry on February 22, 2017, 02:20:03 AM
Please make sure if the 'data' has the correct data before loading into the form. data=getParametersQtaSample(r.dati_ricerca,id_tab); console.log(data); $('#dati_dna').form('load', data);
Title: Re: Combogrid cannot read property 'idField' of null
Post by: acreonte82 on February 22, 2017, 07:48:44 AM
yes the data array is correct. if i found in the json array ... "dna_position":null ... it is because i've not value to set in the combogrid So if i've null value , how i can prevent the error showed in console?
Title: Re: [SOLVED] Combogrid cannot read property 'idField' of null
Post by: acreonte82 on February 28, 2017, 01:45:07 PM
I solved changing the result value from json array I used "" (empty value) instead of null value.
Thanks for all support
|