Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

JQWidgets
Home›Products›JQWidgets›Implement radio button selection in JQWidgets JQXGrid using checkbox

Implement radio button selection in JQWidgets JQXGrid using checkbox

By SibeeshVenu
June 29, 2016
3435
0
Share:
Grid with check box selection

In this post we will see how we can implement radio button selection feature to jQWidgets jQXGrid. As of now in JQXGrid, we don’t have this functionality yet, but still we can do it our self by using check box selection which is already available. We will load the grid with sample data and implement the radio button selection. If you are new to JQX Grid, you can see some tips here. I hope you will like this.

Download Source Code

You can always download the source code from here: Radio button selection in JQXGrid

Background

I am using JQXGrid in one of my project, where I wanted to implement the radio button selection, when I talked with JQXGrid development team, I was said that the functionality is not yet available. But they have given an option as selectionmode: ‘checkbox’ with the help of that property we can implement the requirement. As you know, to load a jQWidget JQX Grid, there you need the following things as mandatory.

  • datafields
  • columns
  • localdata or server side data
  • Using the code

    First of all, load the needed references. You can download the needed files from here.

    [html]
    <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
    <script src="jquery-2.2.3.min.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.edit.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.pager.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.sort.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcheckbox.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.columnsresize.js"></script>
    [/html]

    Now, we are going to set our data source, this time we will use a XML file as data source.

    [xml]
    <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
    <feed xml:base="http://services.odata.org/Northwind/Northwind.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
    <title type="text">Orders</title>
    <id>http://services.odata.org/Northwind/Northwind.svc/Orders</id>
    <updated>2011-12-01T11:55:06Z</updated>
    <link rel="self" title="Orders" href="Orders" />
    <entry>
    <id>http://services.odata.org/Northwind/Northwind.svc/Orders(10248)</id>
    <title type="text"></title>
    <updated>2011-12-01T11:55:06Z</updated>
    <author>
    <name />
    </author>
    <link rel="edit" title="Order" href="Orders(10248)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Customer" type="application/atom+xml;type=entry" title="Customer" href="Orders(10248)/Customer" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Employee" type="application/atom+xml;type=entry" title="Employee" href="Orders(10248)/Employee" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Order_Details" type="application/atom+xml;type=feed" title="Order_Details" href="Orders(10248)/Order_Details" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Shipper" type="application/atom+xml;type=entry" title="Shipper" href="Orders(10248)/Shipper" />
    <category term="NorthwindModel.Order" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
    <m:properties>
    <d:OrderID m:type="Edm.Int32">10248</d:OrderID>
    <d:CustomerID>VINET</d:CustomerID>
    <d:EmployeeID m:type="Edm.Int32">5</d:EmployeeID>
    <d:OrderDate m:type="Edm.DateTime">1996-07-04T00:00:00</d:OrderDate>
    <d:RequiredDate m:type="Edm.DateTime">1996-08-01T00:00:00</d:RequiredDate>
    <d:ShippedDate m:type="Edm.DateTime">1996-07-16T00:00:00</d:ShippedDate>
    <d:ShipVia m:type="Edm.Int32">3</d:ShipVia>
    <d:Freight m:type="Edm.Decimal">32.3800</d:Freight>
    <d:ShipName>Vins et alcools Chevalier</d:ShipName>
    <d:ShipAddress>59 rue de l’Abbaye</d:ShipAddress>
    <d:ShipCity>Reims</d:ShipCity>
    <d:ShipRegion m:null="true" />
    <d:ShipPostalCode>51100</d:ShipPostalCode>
    <d:ShipCountry>France</d:ShipCountry>
    </m:properties>
    </content>
    </entry>
    <entry>
    <id>http://services.odata.org/Northwind/Northwind.svc/Orders(10249)</id>
    <title type="text"></title>
    <updated>2011-12-01T11:55:06Z</updated>
    <author>
    <name />
    </author>
    <link rel="edit" title="Order" href="Orders(10249)" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Customer" type="application/atom+xml;type=entry" title="Customer" href="Orders(10249)/Customer" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Employee" type="application/atom+xml;type=entry" title="Employee" href="Orders(10249)/Employee" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Order_Details" type="application/atom+xml;type=feed" title="Order_Details" href="Orders(10249)/Order_Details" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Shipper" type="application/atom+xml;type=entry" title="Shipper" href="Orders(10249)/Shipper" />
    <category term="NorthwindModel.Order" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
    <m:properties>
    <d:OrderID m:type="Edm.Int32">10249</d:OrderID>
    <d:CustomerID>TOMSP</d:CustomerID>
    <d:EmployeeID m:type="Edm.Int32">6</d:EmployeeID>
    <d:OrderDate m:type="Edm.DateTime">1996-07-05T00:00:00</d:OrderDate>
    <d:RequiredDate m:type="Edm.DateTime">1996-08-16T00:00:00</d:RequiredDate>
    <d:ShippedDate m:type="Edm.DateTime">1996-07-10T00:00:00</d:ShippedDate>
    <d:ShipVia m:type="Edm.Int32">1</d:ShipVia>
    <d:Freight m:type="Edm.Decimal">11.6100</d:Freight>
    <d:ShipName>Toms Spezialitäten</d:ShipName>
    <d:ShipAddress>Luisenstr. 48</d:ShipAddress>
    <d:ShipCity>Münster</d:ShipCity>
    <d:ShipRegion m:null="true" />
    <d:ShipPostalCode>44087</d:ShipPostalCode>
    <d:ShipCountry>Germany</d:ShipCountry>
    </m:properties>
    </content>
    </entry>
    <link rel="next" href="http://services.odata.org/Northwind/Northwind.svc/Orders?$skiptoken=10447" />
    </feed>
    [/xml]

    You can get the full data from the file orders.xml from the solution attached.

    Now create a div element where we can bind the grid.

    [html]
    <div id=’jqxWidget’ style="font-size: 13px; font-family: Verdana; float: left;">
    <div id="jqxgrid">
    </div>
    </div>
    [/html]

    Now we will define our grid as follows.

    [js]
    $("#jqxgrid").jqxGrid(
    {
    width: 850,
    height: 450,
    source: dataAdapter,
    sortable: true,
    selectionmode: ‘checkbox’,
    altrows: true,
    ready: function () {
    $(‘#columntablejqxgrid .jqx-checkbox-default’).hide();
    },
    columns: [
    { text: ‘Ship Name’, datafield: ‘ShipName’, width: 250 },
    { text: ‘Shipped Date’, datafield: ‘ShippedDate’, width: 100, cellsformat: ‘yyyy-MM-dd’ },
    { text: ‘Freight’, datafield: ‘Freight’, width: 150, cellsformat: ‘F2’, cellsalign: ‘right’ },
    { text: ‘Ship City’, datafield: ‘ShipCity’, width: 150 },
    { text: ‘Ship Country’, datafield: ‘ShipCountry’ }
    ]
    });
    [/js]

    As you can see we have applied dataAdapter as the source, below is the definition for your data adapter.

    [js]
    var dataAdapter = new $.jqx.dataAdapter(source);
    [/js]

    Now we will create the source object as follows.

    [js]
    var source =
    {
    datatype: "xml",
    datafields: [
    { name: ‘ShippedDate’, map: ‘m\\:properties>d\\:ShippedDate’, type: ‘date’ },
    { name: ‘Freight’, map: ‘m\\:properties>d\\:Freight’, type: ‘float’ },
    { name: ‘ShipName’, map: ‘m\\:properties>d\\:ShipName’, type: ‘string’ },
    { name: ‘ShipAddress’, map: ‘m\\:properties>d\\:ShipAddress’, type: ‘string’ },
    { name: ‘ShipCity’, map: ‘m\\:properties>d\\:ShipCity’, type: ‘string’ },
    { name: ‘ShipCountry’, map: ‘m\\:properties>d\\:ShipCountry’, type: ‘string’ }
    ],
    root: "entry",
    record: "content",
    id: ‘m\\:properties>d\\:OrderID’,
    url: url
    };
    [/js]

    As the grid definition is over,it is time to run our application and check whether the grid is loading fine or not.

    Grid with check box selection

    Grid with check box selection

    what do you see? You are able to do multiple selection right? But what do we needed? A radio button selection, isn’t it? So we are suppose to able to select only one row right?. This is why, we haven’t done the needed implementation yet. Let us add some script then.

    [js]
    $(‘#jqxgrid’).on(‘rowselect’, function (event) {
    // event arguments.
    var args = event.args;
    // row’s bound index.
    var rowBoundIndex = args.rowindex;
    var selectedIndexes = $(‘#jqxgrid’).jqxGrid(‘selectedrowindexes’);
    for (var i = 0; i < selectedIndexes.length; i++) {
    if (rowBoundIndex !== selectedIndexes[i]) {
    $(‘#jqxgrid’).jqxGrid(‘unselectrow’, selectedIndexes[i]);
    }
    }
    });
    [/js]

    We are just deleting the other row selection in the event rowselect. Now run your application again, I am sure you will be able to select only one row at a time.

    Grid with radio button selection

    Grid with radio button selection

    Now we can see the complete code.

    Complete code

    [html]
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />

    <script src="jquery-2.2.3.min.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxdata.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxmenu.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.edit.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.selection.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.pager.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxlistbox.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxdropdownlist.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.sort.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcheckbox.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxgrid.columnsresize.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
    var url = "orders.xml";

    // prepare the data
    var source =
    {
    datatype: "xml",
    datafields: [
    { name: ‘ShippedDate’, map: ‘m\\:properties>d\\:ShippedDate’, type: ‘date’ },
    { name: ‘Freight’, map: ‘m\\:properties>d\\:Freight’, type: ‘float’ },
    { name: ‘ShipName’, map: ‘m\\:properties>d\\:ShipName’, type: ‘string’ },
    { name: ‘ShipAddress’, map: ‘m\\:properties>d\\:ShipAddress’, type: ‘string’ },
    { name: ‘ShipCity’, map: ‘m\\:properties>d\\:ShipCity’, type: ‘string’ },
    { name: ‘ShipCountry’, map: ‘m\\:properties>d\\:ShipCountry’, type: ‘string’ }
    ],
    root: "entry",
    record: "content",
    id: ‘m\\:properties>d\\:OrderID’,
    url: url
    };
    var dataAdapter = new $.jqx.dataAdapter(source);

    // create jqxgrid.
    $("#jqxgrid").jqxGrid(
    {
    width: 850,
    height: 450,
    source: dataAdapter,
    sortable: true,
    selectionmode: ‘checkbox’,
    altrows: true,
    ready: function () {
    $(‘#columntablejqxgrid .jqx-checkbox-default’).hide();
    },
    columns: [
    { text: ‘Ship Name’, datafield: ‘ShipName’, width: 250 },
    { text: ‘Shipped Date’, datafield: ‘ShippedDate’, width: 100, cellsformat: ‘yyyy-MM-dd’ },
    { text: ‘Freight’, datafield: ‘Freight’, width: 150, cellsformat: ‘F2’, cellsalign: ‘right’ },
    { text: ‘Ship City’, datafield: ‘ShipCity’, width: 150 },
    { text: ‘Ship Country’, datafield: ‘ShipCountry’ }
    ]
    });

    $(‘#jqxgrid’).on(‘rowselect’, function (event) {
    // event arguments.
    var args = event.args;
    // row’s bound index.
    var rowBoundIndex = args.rowindex;
    var selectedIndexes = $(‘#jqxgrid’).jqxGrid(‘selectedrowindexes’);
    for (var i = 0; i < selectedIndexes.length; i++) {
    if (rowBoundIndex !== selectedIndexes[i]) {
    $(‘#jqxgrid’).jqxGrid(‘unselectrow’, selectedIndexes[i]);
    }
    }
    });
    });
    </script>
    </head>
    <body class=’default’>
    <div id=’jqxWidget’ style="font-size: 13px; font-family: Verdana; float: left;">
    <div id="jqxgrid">
    </div>
    </div>
    </body>
    </html>
    [/html]

    Conclusion

    Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

    Your turn. What do you think?

    A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

    Kindest Regards
    Sibeesh Venu

    TagsJQWidgetsJQX GridRadio button selection in JQWidgets JQXGrid
    Previous Article

    Thank You

    Next Article

    Time Zone Calculator

    0
    Shares
    • 0
    • +
    • 0
    • 0
    • 0

    SibeeshVenu

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

    Related articles More from author

    • Change Header Names Dynamically In JQwidgets JQX grid
      JQWidgetsJQX GridProducts

      Change Header Names Dynamically In JQwidgets JQX grid

      October 28, 2015
      By SibeeshVenu
    • Code SnippetsJQWidgetsJQX GridProducts

      Get jqwidget jqx grid column count

      June 19, 2015
      By SibeeshVenu
    • JQWidgetsJQX GridQ&A

      Filter parameters are always null in server side paging in JQWidget JQX Grid. Why?

      June 29, 2015
      By SibeeshVenu
    • Dynamically apply colour coding in Grid
      JQWidgetsJQX Grid

      Dynamically Apply Colour Coding in Grid With Dynamic Headers And Data

      February 16, 2016
      By SibeeshVenu
    • Change Themes Dynamically In Grid
      JQWidgetsJQX GridProducts

      Change Themes Dynamically In Grid

      October 28, 2015
      By SibeeshVenu
    • Working With JQX Grid With Filtering And Sorting And Searching
      JQWidgetsJQX Grid

      Working With JQX Grid With Filtering And Sorting And Searching

      November 29, 2014
      By SibeeshVenu
    0

    My book

    Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

    YouTube

    MICROSOFT MVP (2016-2022)

    profile for Sibeesh Venu - Microsoft MVP

    Recent Posts

    • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
    • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
    • Easily move data from one COSMOS DB to another
    • .NET 8 New and Efficient Way to Check IP is in Given IP Range
    • Async Client IP safelist for Dot NET
    • Post Messages to Microsoft Teams Using Python
    • Get Azure Blob Storage Blob Metadata Using PowerShell
    • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
    • Integrate Azure App Insights in 1 Minute to .Net6 Application
    • Azure DevOps Service Connection with Multiple Azure Resource Group

    Tags

    Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
    • .NET
    • Achievements
    • ADO.NET
    • Android
    • Angular
    • Arduino
    • Article Of The Day
    • ASP.NET
    • Asp.Net Core
    • Automobile
    • Awards
    • Azure
    • Azure CDN
    • azure devops
    • Blockchain
    • Blog
    • Browser
    • C-Sharp Corner
    • C#
    • Career Advice
    • Code Snippets
    • CodeProject
    • Cognitive Services
    • Cosmos DB
    • CSS
    • CSS3
    • Data Factory
    • Database
    • Docker
    • Drawings
    • Drill Down Chart
    • English
    • Excel Programming
    • Exporting
    • Facebook
    • Fun
    • Gadgets
    • GitHub
    • GoPro
    • High Map
    • HighChart
    • How to
    • HTML
    • HTML5
    • Ignite UI
    • IIS
    • Interview
    • IoT
    • JavaScript
    • JQuery
    • jQuery UI
    • JQWidgets
    • JQX Grid
    • Json
    • Knockout JS
    • Linux
    • Machine Learning
    • Malayalam
    • Malayalam Poems
    • MDX Query
    • Microsoft
    • Microsoft ADOMD
    • Microsoft MVP
    • Microsoft Office
    • Microsoft Technologies
    • Microsoft Windows
    • Microsoft Windows Server
    • Mobile
    • MongoDB
    • Monthly Winners
    • MVC
    • MVC Grid
    • MySQL
    • News
    • Node JS
    • npm
    • Number Conversions
    • October 2015
    • Office 365
    • Office Development
    • One Plus
    • Outlook
    • Page
    • PHP
    • Poems
    • PowerShell
    • Products
    • Q&A
    • Raspberry PI
    • React
    • SEO
    • SharePoint
    • Skype
    • Social Media
    • Software
    • Spire.Doc
    • Spire.PDF
    • Spire.XLS
    • SQL
    • SQL Server
    • SSAS
    • SSMS
    • Storage In HTML5
    • Stories
    • Third Party Software Apps
    • Tips
    • Tools
    • Translator Text
    • Uncategorized
    • Unit Testing
    • UWP
    • VB.Net
    • Videos
    • Virtual Machine
    • Visual Studio
    • Visual Studio 2017
    • Wamp Server
    • Web API
    • Web Platform Installer
    • Webinars
    • WebMatrix
    • Windows 10
    • Windows 7
    • Windows 8.1
    • Wordpress
    • Writing

    ABOUT ME

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

    Contact Me

    • info@sibeeshpassion.com

    Pages

    • About
    • Search
    • Privacy Policy
    • About
    • Search
    • Privacy Policy
    © Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
    Go to mobile version