flexigrid records

Evan Cutler
Evan Cutler used Ask the Experts™
on
Greetings EE warriors....

I am working on a Flexigrid from XML via ashx....

I am trying to troubleshoot why my grid does this:

 Screenshot of Flexigrid output with 5 records.There are only five records in the database right now.  Also, if I change the rows-per-page dropdown, the numbers skew even further.
 
Here is my aspx page:
 
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Scratchpad.aspx.cs" Inherits="Scratchpad_Scratchpad" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <script src="../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/Grid/flexigrid.pack.js" type="text/javascript"></script>
    <script src="../Scripts/Grid/flexigrid.js" type="text/javascript"></script>
    <link href="../Styles/grid/flexigrid.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/grid/flexigrid.pack.css" rel="stylesheet" type="text/css" />
    <script language="javascript" type="text/javascript">
        $("document").ready(function () {
            $("#adgrid").flexigrid({
                url: '../data_services/Ads.ashx',
                dataType: 'xml',
                colModel: [
											    { display: 'Title', name: 'Title', width: 150, sortable: true, align: 'left' },
											    { display: 'Text', name: 'Text', width: 250, sortable: true, align: 'left' },
                                                { display: 'Date Entered', name: 'Date', width: 100, sortable: true, align: 'left' },
                                                { display: 'List of Concentrations', name: 'fields', width: 200, sortable: false, align: 'left' }
											    ],
                searchitems: [
											    { display: 'Title', name: 'title' },
											    { display: 'Text', name: 'Text', isdefault: true }
											    ],
                buttons: [
                                                { name: 'Add', bclass: 'add', onpress: addrow },
                                                { name: 'Delete', bclass: 'delete', onpress: deleterow },
                                                { name: 'Edit', bclass: 'edit', onpress: editrow }
                                                ],
                sortname: "Title",
                sortorder: "asc",
                usepager: true,
                singleSelect: true,
                title: 'Advertisements',
                useRp: true,
                Rp: 10,
                showTableToggleBtn: true,
                width: "auto",
                height: 200
            });

            function addrow() {
                alert("addrow clicked");
            };

            function deleterow() {
                alert("delterow clicked");
            };

            function editrow() {

                alert("edit row clicked");
            };

        });

	</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">


<table id="adgrid"></table>
</asp:Content>

Open in new window


and the XML out from the ashx:
 
- <rows>
  <page>1</page> 
  <total>5</total> 
- <row id="1">
- <cell>
- <![CDATA[ The New Research
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed et justo dui, ut commodo justo. Aliquam tincidunt odio a nisi scelerisque vitae dignissim ante congue. Vestibulum id augue elit. Quisque rutrum turpis nec augue hendrerit volutpat. Fusce venenatis sem sapien, eu consequat sem. Ut auctor ullamcorper vestibulum. Nulla ac enim vel nisl gravida bibendum. Integer felis sapien, sagittis sed placerat sit amet, porttitor ut elit. Aenean et nisi quis neque ultricies fringilla. Cras eleifend, mauris a congue adipiscing, lorem odio pretium augue, eu rhoncus massa ligula nec quam. Vestibulum blandit malesuada nunc, nec posuere neque consectetur vel. Nulla pulvinar nibh a dui vestibulum auctor. 
  ]]> 
  </cell>
- <cell>
- <![CDATA[ 7/30/2011
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Primates, Diptera, Fabales
  ]]> 
  </cell>
  </row>
- <row id="2">
- <cell>
- <![CDATA[ The Second New Research
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam viverra odio vitae nisl ultricies sit amet imperdiet risus hendrerit. Fusce elementum ipsum in justo rhoncus lacinia. Sed metus massa, tincidunt eget feugiat sit amet, commodo malesuada elit. Praesent posuere eleifend sagittis. Aliquam erat volutpat. Vivamus sagittis congue purus, non facilisis nunc mollis consectetur. Cras ante libero, tincidunt ut congue ac, malesuada aliquam sapien. Sed condimentum rhoncus bibendum. Nullam eros ante, tempus laoreet fringilla nec, pharetra vel ipsum. Nunc tortor sem, rutrum ut ultrices ut, cursus a turpis. Fusce at neque ut libero sodales pharetra. Quisque sed ligula lacus. Quisque vel odio enim. Nullam iaculis mollis tellus, nec tristique nulla porttitor vel. Curabitur dolor mauris, adipiscing vel laoreet et, bibendum eget nisl. Quisque sit amet mattis diam.
  ]]> 
  </cell>
- <cell>
- <![CDATA[ 7/30/2011
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Primates, Brachycera
  ]]> 
  </cell>
  </row>
- <row id="3">
- <cell>
- <![CDATA[ The Third New Research
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ut nunc nec dui suscipit blandit. Etiam magna risus, mollis et volutpat in, rutrum in ligula. Nunc nisi orci, sollicitudin sit amet vehicula vitae, imperdiet et mauris. Ut posuere hendrerit mi, id pellentesque leo convallis sit amet. Donec dolor mauris, porta ac consequat quis, volutpat vel felis. Duis tristique, nisi quis malesuada rhoncus, massa nisi porta felis, non aliquet eros nibh quis enim. Cras id dolor eu lectus dictum hendrerit. Duis sagittis tortor ut mauris tristique vulputate. Integer ac elit risus, quis imperdiet augue. Praesent fringilla risus in sapien congue convallis. Quisque in leo a lectus mollis viverra.
  ]]> 
  </cell>
- <cell>
- <![CDATA[ 7/30/2011
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Drosophilidae, Hominidae
  ]]> 
  </cell>
  </row>
- <row id="4">
- <cell>
- <![CDATA[ The Fourth Research
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.
  ]]> 
  </cell>
- <cell>
- <![CDATA[ 7/20/2011
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Brachycera
  ]]> 
  </cell>
  </row>
- <row id="5">
- <cell>
- <![CDATA[ The Fifth Research
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur nec dignissim urna. Maecenas quam augue, varius in venenatis sed, lacinia vitae quam. Nunc nec tellus tortor. Aliquam adipiscing scelerisque felis nec viverra. In hac habitasse platea dictumst. Nulla facilisi. Fusce leo neque, vestibulum eget molestie vel, commodo tincidunt risus. Proin euismod facilisis nisl id lobortis. Etiam laoreet urna laoreet mi fringilla euismod. Quisque volutpat est eu nunc tempor volutpat venenatis libero bibendum. Mauris fringilla faucibus dolor. Proin egestas pretium est nec hendrerit. Aenean a leo vel massa congue sollicitudin. Nulla mauris sapien, ultricies id tincidunt in, aliquam ac elit. Donec et odio mi, consequat tristique velit. Integer iaculis, elit nec accumsan pharetra, risus odio ornare nibh, in vulputate neque nulla et purus. Morbi sollicitudin lacinia lectus, eu ultrices justo sollicitudin et.
  ]]> 
  </cell>
- <cell>
- <![CDATA[ 7/25/2011
  ]]> 
  </cell>
- <cell>
- <![CDATA[ Fabineae, Fabaceae
  ]]> 
  </cell>
  </row>
  </rows>

Open in new window


Appreciate it.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
leakim971Multitechnician
Top Expert 2014

Commented:
please provide the code for : Ads.ashx
look like I get the right number of item with a simple code
Clipboard02.jpg
Evan CutlerVolunteer Chief Information Officer

Author

Commented:
Code Provided...Thanks :)
 
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text.RegularExpressions;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "text/xml";
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        //context.Response.Headers.Add("Pragma", "no-cache");
        //context.Response.Headers.Add("Cache-Control", "no-cache, must-revalidate");
        
        ConcentrationTree ct = new ConcentrationTree();
        int page = 1;
        int rp = 10;
        string sortname = "title";
        string sortorder = "ascending";
        double total;

        if (context.Request.Params.Get("page") != null)
        {
            page = int.Parse(context.Request.Params.Get("page").ToString());
        };

        if (context.Request.Params.Get("rp") != null)
        {
            page = int.Parse(context.Request.Params.Get("rp").ToString());
        };

        if (context.Request.Params.Get("sortname") != null)
        {
            sortname = context.Request.Params.Get("sortname").ToString();
        };

        if (context.Request.Params.Get("sortorder") != null)
        {
            if (context.Request.Params.Get("sortorder").ToString() == "desc" || context.Request.Params.Get("sortorder").ToString() == "descending")
            {
                sortorder = "descending";
            };
        };

        
        total = (from count in ct.Advertisements
                       select count).Count();


        
        List<String> fieldlist = new List<string>();

        var adlist = (from ad in ct.Advertisements
                      select ad);

        XDocument AdXML = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes")
            );

        XElement rows = new XElement("rows");
        XElement pager = new XElement("page", page.ToString());
        XElement totals = new XElement("total", total.ToString());
        
        
        AdXML.Add(rows);
        rows.Add(pager);
        rows.Add(totals); 
        
        foreach (var ad in adlist)
        {
            XElement row = new XElement("row",
                new XAttribute ("id", ad.PK),
                new XElement("cell", new XCData(ad.Title)),
                new XElement("cell", new XCData(Regex.Replace(ad.Text, "<.*?>", string.Empty))),
                new XElement("cell", new XCData(ad.date_entered.ToShortDateString()))
                );

            rows.Add(row);

            fieldlist.Clear();
            var fields = from field in ct.Concentrations
                         join ads in ct.Concentration_Advertisements on field.PK equals ads.FK_Concentration
                         where ads.FK_Advertisement == ad.PK
                         select field;

            foreach (var field in fields)
            {
                fieldlist.Add(field.Concentration1);
            }
            
        XElement fldlst = new XElement("cell",  new XCData(string.Join(", ", fieldlist)));
        row.Add(fldlst);

        };


        context.Response.Write(AdXML);
                     
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:
Cant locate ConcentrationTree
Would be great if you've a lin to see the page running?
Look like your XML is malformed
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Evan CutlerVolunteer Chief Information Officer

Author

Commented:
Sorry it took me so long....
ConcentrationTree is the name from the dbml.

here is the link of the table running: http://www.cutlerplace.net/scratchpad/scratchpad.aspx

here is the file with the XML.
http://www.cutlerplace.net/data_services/Ads.ashx

Thanks.
leakim971Multitechnician
Top Expert 2014

Commented:
OK, to start you should remove a script and css, currently you're using the packed and unpacked versions :
    <script src="../Scripts/Grid/flexigrid.js" type="text/javascript"></script>
    <script src="../Scripts/Grid/flexigrid.pack.js" type="text/javascript"></script>
    <link href="../Styles/grid/flexigrid.css" rel="stylesheet" type="text/css" />
    <link href="../Styles/grid/flexigrid.pack.css" rel="stylesheet" type="text/css" />

Open in new window

you only need :
    <script src="../Scripts/Grid/flexigrid.js" type="text/javascript"></script>
    <link href="../Styles/grid/flexigrid.css" rel="stylesheet" type="text/css" />

Open in new window

or (packed ones):
    <script src="../Scripts/Grid/flexigrid.pack.js" type="text/javascript"></script>
    <link href="../Styles/grid/flexigrid.pack.css" rel="stylesheet" type="text/css" />

Open in new window

With a bit of luck it should fix your problem else, please use the unpacked version (first ones) to debug your code easily, thanks
leakim971Multitechnician
Top Expert 2014

Commented:
it's a good practice to put css before javascript :
    <link href="../Styles/grid/flexigrid.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/Grid/flexigrid.js" type="text/javascript"></script>

Open in new window

Evan CutlerVolunteer Chief Information Officer

Author

Commented:
I did not know that CSS came before js...
good to know.

however, still not counting right.
http://www.cutlerplace.net/scratchpad/scratchpad.aspx
leakim971Multitechnician
Top Expert 2014

Commented:
I see you return :
<rows>¿
<page>¿15¿</page>¿
<total>¿5¿</total>
...

Open in new window


so page is set to 15 !?
leakim971Multitechnician
Top Expert 2014

Commented:
you set rp to 15 :

                rp: 15,
                showTableToggleBtn: true,
                width: 750,
                height: 200
            });

            $('#ads').flexigrid().find('tr').live('click', {}, function (ev) {

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:
forget my comment lol
leakim971Multitechnician
Top Expert 2014

Commented:
the problem is just the
<page>15</page>

Open in new window

leakim971Multitechnician
Top Expert 2014

Commented:
line 30 to 38 :

        if (context.Request.Params.Get("page") != null)
        {
            page = int.Parse(context.Request.Params.Get("page").ToString());
        };

        if (context.Request.Params.Get("rp") != null)
        {
            page = int.Parse(context.Request.Params.Get("rp").ToString());
        };

Open in new window


You're using the same variable for rp and page
Evan CutlerVolunteer Chief Information Officer

Author

Commented:
ok...well, fixed that... lol

but that doesn't change the XML output...
do you think it's a setting at Flexigrid?
leakim971Multitechnician
Top Expert 2014

Commented:
it's not fixed, Ads.ashx still return 15 in <page> node
leakim971Multitechnician
Top Expert 2014

Commented:
<rows>
  <page>15</page>
  <total>5</total>
  <row id="1">
    <cell><![CDATA[The New Research]]></cell>
    <cell><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing...]]></cell>
    <cell><![CDATA[7/30/2011]]></cell>
    <cell><![CDATA[Primates, Diptera, Fabales]]></cell>
  </row>
  <row id="2">
    <cell><![CDATA[The Second New Research]]></cell>
    <cell><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing...]]></cell>
    <cell><![CDATA[7/30/2011]]></cell>
    <cell><![CDATA[Primates, Brachycera]]></cell>
  </row>
  <row id="3">
    <cell><![CDATA[The Third New Research]]></cell>
    <cell><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing...]]></cell>
    <cell><![CDATA[7/30/2011]]></cell>
    <cell><![CDATA[Drosophilidae, Hominidae]]></cell>
  </row>
  <row id="4">
    <cell><![CDATA[The Fourth Research]]></cell>
    <cell><![CDATA[Pellentesque habitant morbi tristique senectus et ...]]></cell>
    <cell><![CDATA[7/20/2011]]></cell>
    <cell><![CDATA[Brachycera]]></cell>
  </row>
  <row id="5">
    <cell><![CDATA[The Fifth Research]]></cell>
    <cell><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing...]]></cell>
    <cell><![CDATA[7/25/2011]]></cell>
    <cell><![CDATA[Fabineae, Fabaceae]]></cell>
  </row>
</rows>

Open in new window


if you call it directly it's ok, we get
<page>1</page>

Open in new window

Evan CutlerVolunteer Chief Information Officer

Author

Commented:
ok...then how did you get <page>15</page>?

I'm not seeing how.
leakim971Multitechnician
Top Expert 2014

Commented:
firebug
Evan CutlerVolunteer Chief Information Officer

Author

Commented:
ok, I see it...
why does it do that?
Multitechnician
Top Expert 2014
Commented:
you still have a bug in Ads.ashx, there's no other reason, perhaps you need to restart IIS due caching problem?
Evan CutlerVolunteer Chief Information Officer

Author

Commented:
YOU ARE A GENIUS!!!!!!!

Lots of points to you and your friends.
:)

Thanks much.
leakim971Multitechnician
Top Expert 2014

Commented:
thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial