Jqgrid using Coldfusion Json data - Grouping will not work? - jqgrid
‘Hi I'm new using jquery and the jqgrid and have hit an issue I cant work out and have searched every where for answers and have found none.'
'I'm developing within the coldfusion environment and my grid loads and populates fine but the grouping that I have enabled is not working and I think it maybe my JSON data format but cant be sure.'
'My JSON format looks like this:'
{"ROWS":[["Account Enquiry","Adding a myki",77.0,105.0,-0.27,385.0,601.0,-0.36], ["Account Enquiry","Archive cards",0.0,64.0,0.00,451.0,17.0,25.53],["Account Enquiry","Cancelling an account",27.0,52.0,-0.48,164.0,165.0,-0.01],["Account Enquiry","Change of details",305.0,483.0,-0.37,2400.0,2311.0,0.04],["Account Enquiry","Consolidate cards",0.0,84.0,0.00,685.0,45.0,14.22],["Account Enquiry","Obtain Balance",560.0,1272.0,-0.56,6828.0,3604.0,0.89],["Account Enquiry","Removing a myki",16.0,28.0,-0.43,87.0,112.0,-0.22],["Account Enquiry","Retrieve cards",0.0,13.0,0.00,56.0,1.0,55.00],["Account Enquiry","Tax invoice request",11.0,33.0,-0.67,103.0,42.0,1.45],["Account Enquiry","Transaction history",502.0,1035.0,-0.51,5370.0,3334.0,0.61]],"PAGE":1.0,"RECORDS":10,"TOTAL":1.0}
'Using the following CFC.’
<cfcomponent displayname="InvoiceMgr" output="false">
<cffunction name="getInvoices" access="remote" output="false" returnformat="json">
<cfset invoices = ArrayNew(1) />
<cfquery datasource="CS_1″ name="q">
SELECT top 10 name, segment, current_month, previous_month, convert(numeric(17,2),m_variance) as m_variance, current_year, previous_year, Convert(numeric(17,2),y_variance) as y_variance
FROM dbo.csg_disposition_dashboard_4
group by name, segment, current_month, previous_month, m_variance, current_year, previous_year,y_variance
order by name asc
</cfquery>
<cfloop query="q">
<cfset invoices[currentrow] = [#name#,#segment#,#current_month#, #previous_month#,#m_variance#, #current_year#, #previous_year#,#y_variance#]>
</cfloop>
<cfset str = {total=1, page=1, records=#q.recordcount#, rows=invoices}>
<cfreturn str />
</cffunction>
</cfcomponent>
‘The Javascript i'm using is:’
jqGrid
<!–<link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.7.2/css/ui.jqgrid.css" />–>
<script type="text/javascript" src="/Jquery/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/Jquery/js/jquery-ui-1.8.14.custom.min.js">
</script>
<script type="text/javascript" src="/Jquery/src/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.base.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.common.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.formedit.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.inlinedit.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.custom.js"></script>
<script type="text/javascript" src="/Jquery/src/jquery.fmatter.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.grouping.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.treegrid.js"></script>
<script type="text/javascript" src="/Jquery/src/grid.jqueryui.js"></script>
<!–<script type="text/javascript" src="/Jquery/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="/Jquery/js/jquery.jqGrid.min.js"></script>–>
<script type="text/javascript">
$(document).ready(function(){
$("#list").jqGrid({
url:'contacts1.cfc?method=getInvoices',
datatype: 'json',
colNames:['Source','Segment','August','July','Variance','2011','2010','Variance'],
colModel :[
{name:'name',index:'name', width:250, editable:true},
{name:'segment',index:'segment', width:200},
{name:'current_month',index:'current_month', width:100,align:"center",sorttype:"int",summaryType:'sum'},
{name:'previous_month',index:'previous_month', width:100,align:"center",sorttype:"int",summaryType:'sum'},
{name:'m_variance',index:'m_variance', width:80,align:"center",sorttype:"int",summaryType:'avg'},
{name:'current_year',index:'current_year', width:100,align:"center",sorttype:"int",summaryType:'sum'},
{name:'previous_year',index:'previous_year', width:100,align:"center",sorttype:"int",summaryType:'sum'},
{name:'y_variance',index:'y_variance', width:80,align:"center",sortable:false,summaryType:'avg'}],
pager: $('#pager'),
rowList:[100,300,600,1000],
width: 'auto',
height: 'auto',
sortname: "name",
sortorder: "desc",
viewrecords: true,
jsonReader: {
root: "ROWS",
page: "PAGE",
total: "TOTAL",
cell: "",
id: "id",
caption: "Disposition Codes",
grouping:true,
groupingView : {
groupField : ['name'],
groupDataSorted : true
}
}}
);
});
</script>
</head>
<body>
<table id="list" class="scroll"> <div id="pager" class="scroll" style="text- align:center;"> </body>
</html>
‘I really would like some help on this as I'm at the end of sanity, head hitting desk.
Looking forward to someone knowing the answer.
Regards
Mayson’
Make sure your jQGrid version is 3.8+, as it will not work for previous version. The way you are defining your jqgrid script files, it seems like you are using older version
Related
Difficulty implementing Chart widget with Kendo UI
I'm creating a mobile app using KendoUI in the Telerik AppBuilder. I created a blank view to hold my chart and then went in to start adding the code. I cannot get the chart to appear. These are the scripts referenced in my index.html: <script src="cordova.js"></script> <script src="kendo/js/jquery.min.js"></script> <script src="kendo/js/kendo.mobile.min.js"></script> <script src="app.js"></script> <script src="lib/progress/progress.all.min.js"></script> <script src="dataProviders/progressDataProvider.js"></script> Here is the code of my chart view: <div data-role="view" data-title="Audit Tracker" data-layout="main" data- model="app.auditTracker" data-show="app.auditTracker.onShow" data-after-show="app.auditTracker.afterShow"> <div id="chart"> </div> </div> And here is the code in the associated JavaScript file: 'use strict'; app.auditTracker = kendo.observable({ onShow: function () {}, afterShow: function () {} }); (function(parent) { $("#chart").kendoChart({ title: { text: "Audit Tracker" }, series: [ {name: "Audits Completed", data: [5,10,15,3]} ], categoryAxis: { categories: ["January", "February", "March", "April"] } }); })(app.auditTracker); What am I doing wrong here? This seems like it should be simple! Thanks in advance for the help.
My problem was that I did not have the correct framework files referenced in my index.html. Here are the files that I ended up using as far as the framework goes: <script src="cordova.js"></script> <script src="jquery.min.js"></script> <script src="kendo.all.min.js"></script> <link rel="stylesheet" href="kendo.common.min.css" /> <link rel="stylesheet" href="kendo.default.min.css" /> <link rel="stylesheet" href="kendo.mobile.all.min.css"/>
JQuery UI Accordion not working with AJAX loaded content
I am attempting to dynamically load a page of product info, that has an accordion menu for the user to browse. I bring in the content for the accordion dynamically using AJAX after a button click. The HTML for the accordion is showing up in the manner that it should, but the accordion "method" isn't being executed to modify the content into an accordion. Imports: <link rel="stylesheet" href="css/supersized.css" type="text/css" media="screen" /> <link rel="stylesheet" href="theme/supersized.shutter.css" type="text/css" media"screen" /> <link rel="stylesheet" href="css/NewSite.css" type="text/css" media="screen" /> <link rel="stylesheet" href="/resources/demos/style.css"> <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <script type="text/javascript" src="js/jquery.easing.min.js"></script> <script type="text/javascript" src="/development-bundle/ui/jquery.ui.core.js"></script> <script type="text/javascript" src="/development-bundle/ui/jquery.ui.widget.js"></script> <script type="text/javascript" src="/development-bundle/ui/jquery.ui.accordion.js"></script> <script type="text/javascript" src="js/supersized.3.2.7.min.js"></script> <script type="text/javascript" src="theme/supersized.shutter.min.js"></script> <script type="text/javascript" src="js/jquery.ModalWindow.js"></script> Accordion Call in the JQuery: <script type="text/javascript"> jQuery(document).on('click', '.subMenuItem', function() { event.preventDefault(); var subMenuItemID = '#' + $(this).attr('id'); var menuItemContent = $('#MenuItemContent'); var mainCategory = $(this).attr('id').split('xx')[0]; var subCategory = $(this).attr('id').split('xx')[1]; $.ajax({ url: '/php/SubMenuItemContent.php', data: { MainCategory: mainCategory, SubCategory: subCategory }, success: function(result) { menuItemContent.html(result); } }); $('.accordion').accordion({ heightStyle: "content", active: false, collapsible: true }); } }); </script> The resultant Markup from the AJAX is correct, but the accordion doesnt display properly, it displays as a normal block of H3's and divs.
Two things, first you have an extra } at the end of your script. Second, the accordion content isn't loaded correctly because the accordion DOM elements are not yet loaded (they are loaded in your AJAX call), so put the following your SubMenuItemContent.php file: <script> jQuery(document).ready(function($) { $('.accordion').accordion({ heightStyle: "content", active: false, collapsible: true }); }) </script> to init the accordion that is loaded. Alternatively you could try moving the accordion() call inside your success callback like so: success: function(result) { menuItemContent.html(result); $('.accordion').accordion({ heightStyle: "content", active: false, collapsible: true }); } But I've had more success with the previous method, for whatever reason.
kendoui: Bind Remote datasource to drop down list in template
I have a edit template using a list view and want a drop down list that is populated from a remote source. But the drop down list just shows the loading icon. Here is the DropDownList DataSource. var dsTitles = new kendo.data.DataSource({ transport: { read: "../data/options/", dataType: "json" }, serverFiltering: true, filter: [{ field: "category_opt", operator: "eq", value: "title" }] }); and here is what I'm putting in the edit template <input name="title_clt" data-bind="value:title_clt" data-value-field="value_opt" data-text-field="label_opt" data-source="dsTitles" data-role="dropdownlist" required validationMessage="Required" /> any help would be great.
Your code is basically fine but there a couple of question that you might have missed. Since you are defining the DataSource saying data-source="dsTitles" as part of the HTML the order on how you define things is pretty important. The first thing that gets defined is the HTML. Which means that dsTitle should be global. Then, after the input is processed is when you should call kendo.init. So, it should be something like this: <html> <head> <meta charset="UTF-8"/> <title>OnaBai - KendoUI DrowDownList</title> <!-- Kendo UI Web styles--> <link href="styles/kendo.common.min.css" rel="stylesheet" type="text/css"/> <link href="styles/kendo.default.min.css" rel="stylesheet" type="text/css"/> <!-- Kendo UI Web scripts--> <script src="js/jquery.min.js" type="text/javascript"></script> <script src="js/kendo.web.min.js" type="text/javascript"></script> <!-- Web Page styling --> <style type="text/css"> </style> <script type="text/javascript"> var dsTitles = new kendo.data.DataSource({ transport: { read: "../data/options/", dataType: "json" }, serverFiltering: true, filter: [{ field: "category_opt", operator: "eq", value: "title" }] }); $(document).ready(function () { kendo.init("input"); }); </script> </head> <body> <input name="title_clt" data-bind="value:title_clt" data-value-field="value_opt" data-text-field="label_opt" data-source="dsTitles" data-role="dropdownlist" required validationMessage="Required" /> </body> </html>
I think the answer might be as simple as using a Kendo DropDownListFor, which will be populated with the given data.
error $("#list").jqGrid is not a function in mvc3 razor
I have written a function in javascript for JQgrid.I checked it in JSFiddle and in JSfiddle it tells me that "your javascript code is valid".But when I run it in mvc3 razor, view grid is not display and it gives me an error in firebug that TypeError: $("#list").jqGrid is not a function below is my view file code #model CBS.Models.Gledg #{ ViewBag.Title = "JV"; } <h2>JV</h2> <link href="/Content/jquery-ui.css" rel="stylesheet" type="text/css" /> <link href="/Content/site.css" rel="stylesheet" type="text/css" /> <script src="/Scripts/jquery-1.5.1.js" type="text/javascript"></script> <script src="#Url.Content("~/Scripts/jquery-ui-1.8.7.min.js")" type="text/javascript"></script> <script src="#Url.Content("~/Scripts/jquery-ui.multiselect.js")"type="text/javascript"></script> <script src="#Url.Content("~/Scripts/jquery.tmpl.min.js")" type="text/javascript"></script> <script src="#Url.Content("~/Scripts/jquery.jqGrid.locale-en-4.1.2.js")" type="text/javascript"></script> <script src="#Url.Content("~/Scripts/jquery.jqGrid-4.1.2.min.js")" type="text/javascript"></script> <script src="/Scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script> <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $(function () { $("#list").jqGrid({ url: '/Home/GetJVLedg()/', datatype: 'json', mtype: 'GET', colNames: ['Code', 'Remarks', 'Debit'], colModel: [ { name: 'Code', index: 'Code', width: 40, align: 'left' }, { name: 'Remarks', index: 'Remarks', width: 240, align: 'left' }, { name: 'Debit', index: 'Debit', width: 200, align: 'left'}], pager: jQuery('#pager'), rowNum: 10, rowList: [5, 10, 20, 50], sortname: 'Code', sortorder: "desc", viewrecords: true, //imgpath: '/scripts/themes/coffee/images', caption: 'Gledg' }); }); }); </script> <fieldset> <legend> Journal Voucher</legend> <div id="txtArea"> <label> Voucher NO </label> <input type="text" id="" name="VID" maxlength="20" PlaceHolder="Voucher No..." /> <label>Remarks</label> <input type="text" id="" name="Rem" maxlength="150" PlaceHolder="Remarks..." /> <label>Voucher Date</label> <input type="Text" id="datepicker" name="VDate" /> </div> <table id="list" class="scroll"></table> <div id="pager" class="scroll" style="text-align:center;"></div> </fieldset> I searched a lot but no solution is found which can solve my problem. help me
Place your code inside $(document).ready(function (){}) then it will work. And make sure that you have mentioned all your script&css reference links to get JQGrid in head section
jqplot - uncaught exception - No data
my json file looks like {"items":[ {"date":"2012-03-12","scoreMin":"9","scoreMax":"25","scoreAverage":"20.39","scoreSTD":"3.86","scoreCount":"133","count20":"73","count25":"46"}, {"date":"2012-03-13","scoreMin":"9","scoreMax":"25","scoreAverage":"20.9","scoreSTD":"4.25","scoreCount":"99","count20":"56","count25":"46"}, {"date":"2012-03-14","scoreMin":"9","scoreMax":"25","scoreAverage":"20.9","scoreSTD":"4.25","scoreCount":"99","count20":"56","count25":"46"}, {"date":"2012-03-15","scoreMin":"9","scoreMax":"25","scoreAverage":"20.9","scoreSTD":"4.25","scoreCount":"99","count20":"56","count25":"46"}, {"date":"2012-09-15","scoreMin":"5","scoreMax":"24","scoreAverage":"18.55","scoreSTD":"5.65","scoreCount":"100","count20":"45","count25":"0"}, {"date":"2012-09-16","scoreMin":"5","scoreMax":"24","scoreAverage":"18.55","scoreSTD":"5.65","scoreCount":"100","count20":"45","count25":"0"}, {"date":"2012-09-17","scoreMin":"5","scoreMax":"24","scoreAverage":"18.59","scoreSTD":"5.67","scoreCount":"99","count20":"45","count25":"0"}, {"date":"2012-09-18","scoreMin":"5","scoreMax":"24","scoreAverage":"18.64","scoreSTD":"5.67","scoreCount":"100","count20":"46","count25":"0"} ]} and my script is <!DOCTYPE html> <html> <head> <title>Date Axes</title> <script language="javascript" type="text/javascript" src="jqplot/jquery.min.js"></script> <script language="javascript" type="text/javascript" src="jqplot/jquery.jqplot.min.js"></script> <script language="javascript" type="text/javascript" src="jqplot/plugins/jqplot.dateAxisRenderer.min.js"></script> <link rel="stylesheet" type="text/css" href="jqplot/jquery.jqplot.css" /> </head> <body> <h2> Some Statistics</h2> <div id="chartCanvas" style="height: 400px; width: 1000px; align"> </div> <br /> <script type="text/javascript"> $(function(){ $(document).ready(function(){ alert('Document ready'); var objArrayData=[]; var objArray = []; $.getJSON("data.json",function(data){ $.each(data.items, function(i,data){ objArrayData[i] =("['" + data.date + "'," + data.scoreAverage + "]"); }); alert( 'Fetched ' + objArrayData.length + ' items!'); console.log('object Data ' + objArrayData); objArray = ("[" + objArrayData + "]"); console.log('object Array' + objArray); var plot = $.jqplot('chartCanvas', [objArray], { title:'Rubric Average Scores', gridPadding:{right:35}, axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer, tickOptions:{formatString:'%#m/%y'}, //tickOptions:{formatString:'%b-%y'}, min:'March 30, 2012', tickInterval:'1 month', angle: -30, }}, yaxis:{label:'Average Score', }, series:[{lineWidth:3, markerOptions:{style:'square'}}] }); }); }); return false; }); </script> </body> </html> I am getting uncaught exception- No data error Before plotting the chart, I am printing the array and there are all the values that I need. What is missing? Where am I doing wrong? Thanks for your help.
I don't understand why you are feeding data to the objArrayData array in the way you are doing here. The data doesn't become an array just because there are square brackets surrounding them (it will only appear pretty and satisfying and confusing in the cosole.log). Use array.push() instead of the way you are doing it here. And also make sure you make the data.scoreAverage a number before parsing it to the array. You can do it using parseFloat() function. So finally you can feed the data to the array like this. objArrayData.push([data.date,parseFloat(data.scoreAverage)]); Here's the modified working code. <!DOCTYPE html> <html> <head> <title>Date Axes</title> <script language="javascript" type="text/javascript" src="../jquery.min.js"></script> <script language="javascript" type="text/javascript" src="../jquery.jqplot.min.js"></script> <script language="javascript" type="text/javascript" src="../plugins/jqplot.dateAxisRenderer.min.js"></script> <link rel="stylesheet" type="text/css" href="../jquery.jqplot.css" /> </head> <body> <h2> Some Statistics</h2> <div id="chartCanvas" style="height: 400px; width: 1000px; align"> </div> <br /> <script type="text/javascript"> $(function(){ $(document).ready(function(){ var objArrayData=[]; var objArray = []; $.getJSON("data.json",function(data){ $.each(data.items, function(i,data){ objArrayData.push([data.date,parseFloat(data.scoreAverage)]); }); console.log('object Data ' + objArrayData); var plot = $.jqplot('chartCanvas', [objArrayData], { title:'Rubric Average Scores', gridPadding:{right:35}, axes:{xaxis:{renderer:$.jqplot.DateAxisRenderer, tickOptions:{formatString:'%Y-%m-%d'}, //tickOptions:{formatString:'%b-%y'}, min:'March 30, 2012', tickInterval:'1 month', angle: -30, }}, yaxis:{label:'Average Score', }, series:[{lineWidth:3, markerOptions:{style:'square'}}] }); }); }); return false; }); </script> </body> </html> Hope this helps. PS: Make sure you learn about arrays a little more.