Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

jQuery Flexigrid Plugin - newbie help

Posted on 2010-09-01
13
Medium Priority
?
1,013 Views
Last Modified: 2012-05-10
Hi

Can anyone support my attempt to use this jQuery plugin, or know where I can go to get some decent support? I am using a .ashx generic handler and returning xml data but the data won't show up in the html page, any ideas please ????



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
		<title></title>
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
		<script type="text/javascript" src="flexigrid/flexigrid.pack.js"></script>
		<link rel="Stylesheet" href="flexigrid/style.css" media="screen" />
		<script type="text/javascript">
				$("document").ready(function ()
				{
						$("#flex1").flexigrid({
								url: 'dac.ashx',
								dataType: 'xml',
								colModel: [
														{ display: 'ISO', name: 'iso', width: 40, sortable: true, align: 'center' },
														{ display: 'Name', name: 'name', width: 180, sortable: true, align: 'left' },
														{ display: 'Printable Name', name: 'printable_name', width: 120, sortable: true, align: 'left' },
														{ display: 'ISO3', name: 'iso3', width: 130, sortable: true, align: 'left', hide: true },
														{ display: 'Number Code', name: 'numcode', width: 80, sortable: true, align: 'right' }
														],								
								searchitems: [
														{ display: 'ISO', name: 'iso' },
														{ display: 'Name', name: 'name', isdefault: true }
														],
								sortname: "iso",
								sortorder: "asc",
								usepager: true,
								singleSelect: true,
								title: 'Countries',
								useRp: true,
								rp: 15,
								showTableToggleBtn: true,
								width: 700,
								height: 200
						});

				});

		</script>
</head>
<body>
		<table id='flex1'>
		</table>
</body>
</html>

-------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace testproj
{
	public class dac : IHttpHandler
	{

		public void ProcessRequest(HttpContext context)
		{
			context.Response.ContentType = "text/HTML";

			string buf = string.Empty;
			buf += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
			buf += "<rows>";
			buf += "<page>1</page>";
			buf += "<total>2</total>";
			buf += "<row id='ZW'>";
			buf += "<cell>ZW</cell>";
			buf += "<cell>Zimbabwe</cell>";
			buf += "<cell>Zimbabwe</cell>";
			buf += "<cell>ZWE</cell>";
			buf += "<cell>716</cell>";
			buf += "</row>";
			buf += "<row id='ZM'>";
			buf += "<cell>ZM</cell>";
			buf += "<cell>Zambia</cell>";
			buf += "<cell>Zambia</cell>";
			buf += "<cell>ZMB</cell>";
			buf += "<cell>894</cell>";
			buf += "</row>";
			buf += "</rows>";

			context.Response.Write(buf);
		}

		public bool IsReusable
		{
			get
			{
				return false;
			}
		}
	}
}

Open in new window

0
Comment
Question by:jonatec
  • 8
  • 5
13 Comments
 

Author Comment

by:jonatec
ID: 33576825
Ok thanks, but why as a dot net developer should I write a JSON function when it's easy to return xml from ADO.NET ? Question is can I return xml to the Flexigrid ?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 33576876
I don't want to force you to return JSON or anything else, just to propose you the threads.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:jonatec
ID: 33576923
The threads stated major on a JSON solution which I could just paste in and use. However I would like to return xml and process that in a Flexigrid, is that possible? ( The development documention at the Flexigrid web site is very sparse to say the least ).
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 33577583
Use a webservice instead, we get a "Connection Error" with the handler :


using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Xml;

/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public XmlDocument HelloWorld()
    {
//        context.Response.ContentType = "text/HTML";
        XmlDocument xmlDoc = new XmlDocument();

        string buf = string.Empty;
//        buf += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
        buf += "<rows>";
        buf += "<page>1</page>";
        buf += "<total>2</total>";
        buf += "<row id='ZW'>";
        buf += "<cell><![CDATA[ZW]]></cell>";
        buf += "<cell><![CDATA[Zimbabwe]]></cell>";
        buf += "<cell><![CDATA[Zimbabwe]]></cell>";
        buf += "<cell><![CDATA[ZWE]]></cell>";
        buf += "<cell><![CDATA[716]]></cell>";
        buf += "</row>";
        buf += "<row id='ZM'>";
        buf += "<cell><![CDATA[ZM]]></cell>";
        buf += "<cell><![CDATA[Zambia]]></cell>";
        buf += "<cell><![CDATA[Zambia]]></cell>";
        buf += "<cell><![CDATA[ZMB]]></cell>";
        buf += "<cell><![CDATA[894]]></cell>";
        buf += "</row>";
        buf += "</rows>";

//        context.Response.Write(buf); 
        xmlDoc.LoadXml(buf);
        return xmlDoc;
    }
    
}

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 33577621

.....
$("#flex1").flexigrid({
   url: 'WebService.asmx/HelloWorld',
....

Open in new window

0
 

Author Comment

by:jonatec
ID: 33577684
Great. Does the data type matter, ie...

context.Response.ContentType = "text/HTML";

should I change to text/xml  ?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 33577707
it work fine for me without changing anything else in the webservice not you ?
Clipboard02.jpg
0
 

Author Comment

by:jonatec
ID: 33577776
Yeah, that's great thanks !

Point of discussion then before I close this...

Would you agree that JSON formatted data is unecessary when returning data from an ADO.NET dataset and that xml is better to use ?

0
 
LVL 83

Expert Comment

by:leakim971
ID: 33577813
>Point of discussion then before I close this...

You mean you won't give points before having the answer ?
0
 

Author Closing Comment

by:jonatec
ID: 33577911
Thanks.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 33578208
>Would you agree that JSON formatted data is unecessary when returning data from an ADO.NET dataset and that xml is better to use ?

Don't know about ADO.NET or another way to get data fastly.
Create a JSON object may be a long work with .NET but, as you know, for a large amount of data or a lot of requests you save a lot of bandwidth.
Point of view of the client side, most of time, it's easyest to use JSON data than XML data.

I saw first version of flexigrid used only XML.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 33578214
You're welcome! Thanks for the points!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question