Showing posts with label JQueryUI. Show all posts
Showing posts with label JQueryUI. Show all posts

Saturday, March 21, 2020

How to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget

In this tutorial we'll learn how to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget 
This JQueryUI Autocomplete will be showing as follows :



Step by step How to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget



First, we create a new ASPNET HTTP HANDLER, in Visual Studio, as follows:

using System.Web.Script.Serialization;
namespace WEBAPI_AJAX

    public class EmployeeHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string t = context.Request.QueryString["term"];

            Func<string, bool> pred = (w) => { if (w.StartsWith(t)) return true; else return false; };

            List<string> l = new List<string>()  { "albert","andrew","asterix","ddddd","eeeeee","fffffff","gggggggg","hhhhhh","iiiiii"};

            l = l.Where(pred).ToList();
            //context.Response.ContentType = "text/plain";
            context.Response.Write(new JavaScriptSerializer().Serialize(l));
        }

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





Then, we create the HTML file :

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery UI Autocomplete - Default functionality</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <link href="../Content/bootstrap.min.css" rel="stylesheet" />
    <script>
        $(()=>{
       
            $("#tags").autocomplete({
                source:  'http://localhost:58776/HANDLER1.ASHX'
            });
        });
    </script>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="jumbotron">
                <div class="form-group">
                    <label for="tags" class="control-label col-md-2">Tags: </label>
                    <div class="col-md-10">
                        <input class="form-control" id="tags">
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>
</html>




That's all.... 
In this tutorial we've seen how to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget. 
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן











Wednesday, August 21, 2019

MVC Ajax WebGrid with Sorting and Paging

In this Step by step MVC Ajax WebGrid with Sorting and Paging in 10 Minutes 
   we see how to build an Ajax enabled WebGrid using an jQueryUI Theme  in 10 minutes, following this simple steps :

1) Use MVC scaffolding and build your Model and Views
2) Select a jQueryUI Theme & download it
3) In the "Index" View, replace the Table with a WebGrid and enable Ajax


All the code in this tutorial , can be downloaded from the following GitHub repository:
https://github.com/CarmelSoftware/MVC_WebGrid

This is how this sortable paged Ajax WebGrid is shown in the Ripple Mobile Emulator , Nexus Galaxy settings:


MVC Ajax WebGrid with Sorting and Paging


MVC Ajax WebGrid with Sorting and Paging in 10 Minutes


The whole process of creating an Ajax WebGrid with a jQueryUI Theme , is as following:

1) Use MVC scaffolding and build your Model and Views:

First build your MVC project using EDM & Controller scaffolding.


2) Select a jQueryUI Theme & download it

Browse to http://jqueryui.com/themeroller/  , select your Theme, and download it.
After you unzip the folder, you'll see several files in it.
You do not need all of them. Just copy the following 2 files and folder to your MVC project:
MVC Ajax WebGrid with Sorting and Paging1



Paste the files inside your MVC project as follows:

MVC Ajax WebGrid with Sorting and Paging2


As you can see, the ONLY files that we'll use from the jQueryUI theme are the following:

1) JS folder :
     "jquery-X.X.X.min.js" (here get the latest version of jQuery)
     "jquery-ui.min.js"

2) CSS folder :
     "jquery-ui.css"


Add the following references to the _Layout file:

MVC Ajax WebGrid with Sorting and Paging3

There is no need of referencing the "images" folder.
Also, you get the latest version of jQuery framework : at this moment, that version is 2.1.4


3) In the "Index" View, replace the Table with a WebGrid and enable Ajax

Then go to the "Index" view, and comment the Table that was scaffolded there.
Add the following markup to replace it:

<link href="~/Content/index.css" rel="stylesheet" />

@{ var grid = new WebGrid(Model, new[] { "Title", "DatePosted", "MainPicture" }, rowsPerPage: 3, ajaxUpdateContainerId: "gridDIV"); }


<div id="gridDIV">
@grid.GetHtml(tableStyle:"webgrid-table",headerStyle:"webgrid-header",

    columns: new[] {

        grid.Column("ID",format:(item) =>  item.GetSelectLink(item.BlogID.ToString()) ) ,
        grid.Column("Title",format:@<a href='/Blog/Comments/@item.BlogID'><b>@item.Title</b></a>),
        grid.Column("DatePosted","DatePosted", (item) => String.Format("{0:dd/MM/yyyy}", item.DatePosted != null ? item.DatePosted : DateTime.Now )),
        grid.Column("Picture",format:(item) =>
        { return new MvcHtmlString("<a href='/Blog/Comments/" + item.BlogID +
            "'><img src='/Images/"+item.MainPicture+"' style='width:100px;height:100px;'></img></a>");
        }),
  
        grid.Column(
            format:@<div class="ActionsTH">
            @Html.ActionLink("Edit", "Edit", new { id=item.BlogID })
            @Html.ActionLink("Details", "Details", new { id=item.BlogID })
            @Html.ActionLink("Delete", "Delete", new { id=item.BlogID })
        </div>)
    })
</div>

This code enable Ajax on the Grid, which comes already with Sorting and Paging functionality.
Of course, customize this code with your Model's properties.

As you can see, we also reference a "~/Content/index.css" file:
Inside this file, i added background style found in the "images" folder, such as "images/ui-bg_fine-grain" corresponding to the Theme "Pepper-Grinder" .
If you select another Theme, replace the backgrounds accordingly.
Create this CSS file in the Content folder , and paste this style in it:


body {
    background: #f7f3de url("images/ui-bg_fine-grain_15_f7f3de_60x60.png") 50% 50% repeat;
}

.webgrid-table {
    font: italic 11px Verdana;
    width: 100%;
    display: grid;
    border-collapse: separate;
    border: solid 1px #98BF21;
    background: #f8f7f6 url("images/ui-bg_fine-grain_10_f8f7f6_60x60.png") 50% 50% repeat;
    padding: 5px 5px 5px 5px;
    text-align: center;
}

.webgrid-header th {
    width: 150px;    
    background: #eceadf url("images/ui-bg_fine-grain_10_eceadf_60x60.png") 50% 50% repeat;
    color: #FFFFFF !important;
    font: 900 14px Verdana !important;
    padding: 5px 5px 5px 5px;
    text-align: center;
}

.ActionsTH {
    width: 50px;
    background: #eceadf url("images/ui-bg_fine-grain_10_eceadf_60x60.png") 50% 50% repeat;
    color: #FFFFFF !important;
    font: 900 14px Verdana !important;
    padding: 5px 5px 5px 5px;
    text-align: center;
    width: 180px;
}

.webgrid-footer, .webgrid-footer a {
    background-color: #c67f1c;
    color: #FFF;
    font: 900 14px Verdana;
    padding: 3px 3px 3px 3px;
}

.webgrid-alternating-row {
    background-color: #e5d773;
    padding: 5px 5px 5px 5px;
}

.title-column {
    font: 900 13px Verdana;
    text-align: center;
}

.webgrid-img {
    width: 150px;
    height: 150px;
}

.webgrid-table a {
    text-decoration: none;
    color: #808080;
}


Important:
If you do not see the Ajax working (), it is because the jQuery scripts are lacking.
Just cut the jQuery.js file from the _Layout file to the <head> tag :
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
</head>


THE END

To use a Mobile devices Emulator, take a look at this short tutorial on installing the FREE Ripple Emulator.


That's all. Our WebGrid will be displayed this way:
MVC Ajax WebGrid with Sorting and Paging4

MVC Ajax WebGrid with Sorting and Paging5

MVC Ajax WebGrid with Sorting and Paging6





      by Carmel Schvartzman


כתב: כרמל שוורצמן



Thursday, March 31, 2016

Install jQueryUI Themes in your MVC App in 5 Minutes

In this Step by step Install jQueryUI Themes in your MVC App in 5 Minutes 
   we see how to get your chosen jQueryUI Theme and use it inside your MVC application in 5 minutes, following this simple steps :

1) Select a Theme & download it
2) Select ONLY the script and style files you need
3) Reference them from your HTML5 file


This is how this jQueryUI Application is shown in the Ripple Mobile Emulator , for Nexus Galaxy:

Install jQueryUI Themes in your MVC App in 5 Minutes

Install jQueryUI Themes in your MVC App in 5 Minutes 1



Install jQueryUI Themes in your MVC App in 5 Minutes


The whole process of downloading a jQueryUI Theme , selecting the files you need , and using the Theme in your MVC app, are as following:

1) Select a Theme & download it:

Browse to jQueryUI.com , and open the "Themes" page:

Install jQueryUI Themes in your MVC App in 5 Minutes

Select from the ThemeRoller the Theme you want to apply to your web site , clicking the "Download" button :

Install jQueryUI Themes in your MVC App in 5 Minutes

We use the former version because it is more stable .
Check all checkboxes if they are not :


Install jQueryUI Themes in your MVC App in 5 Minutes 2

Download the theme to your machine.


2)  Select ONLY the script and style files you need:

Unzip and open the downloaded theme, as you can see here:

Install jQueryUI Themes in your MVC App in 5 Minutes 3

Copy- paste the CSS and JS folders to your MVC project.
The ONLY files that the theme will need are the following:

1) JS folder :
     "jquery-X.X.X.min.js"
     "jquery-ui-1.9.2.custom.min.js"

2) CSS folder :
     "jquery-ui-1.9.2.custom.css"



Inside the JS folder, replace the jQuery framework script file that comes with the jQueryUI theme, with the latest version:


Install jQueryUI Themes in your MVC App in 5 Minutes

And replace the corresponding reference in the HTML5 file :


Install jQueryUI Themes in your MVC App in 5 Minutes 4



To take advantage of a Mobile Emulator, take a look at this short tutorial on installing the FREE Ripple Emulator.


That's all. Our jQueryUI theme will be displayed this way:

Install jQueryUI Themes in your MVC App in 5 Minutes 5

Install jQueryUI Themes in your MVC App in 5 Minutes 6

Install jQueryUI Themes in your MVC App in 5 Minutes 7






      by Carmel Schvartzman


כתב: כרמל שוורצמן




Sunday, December 27, 2015

Add the jQueryUI to your web site in 5 minutes

In this Step by step Add the jQueryUI to your web site in 5 minutes  post,  we see how to add the jQueryUI style and javascript to your web in 2 short steps.
This is how a web site using jQueryUI is displayed:



And this is how the site looks like in Nexus Galaxy devices :    



Add the jQueryUI to your web site in 5 minutes  

If you are in a hurry and need to add say a nice Calendar to your web, just take a look here at how to add the jQueryUI style and javascripts to your web in this 2 short steps:

1) download the jQueryUI
2) add only this 3 elements to your Web : 1 file CSS - 1 JS and the Images folder. (and discard all the  other files and folders)



1) Download the jQueryUI files:

Browse to  http://jqueryui.com/themeroller/    and select your favorite Theme : 


Click on "Download" and there click again on "Download" :




Save the .zip file somewhere and unzip it.

2) Add only this 3 elements to your Web:

Next, we select only the following 3 files :

 1) The file CSS : jquery-ui.css
 2) The JS file :    jquery-ui.js
 3) The Images folder   "images" :


Paste the files inside your web site project :


Then, import the links to the web page where you want to enable the jQuery components and style :



The style reference must be located in the <head> element.
The scripts will go by the end of the <body> tag, thus ensuring that all HTML5 elements were created , when the compiler will read the scripts.
However, be careful to :
1) referencing the file scripts before you start coding your own javascript code;
2) the "jquery-ui.js" script file must follow the jQuery code "jquery.js" (or "jquery-X.X.X.js") [where "X" is the current version]




That's all. The web site will be shown like this:


1- In Mobile devices : 





2- On Medium and Big desktops:





      by Carmel Schvartzman


כתב: כרמל שוורצמן

Friday, July 18, 2014

Step by step how to add the Twitter Bootstrap to the jQueryUI widgets in Asp.Net MVC

        By Carmel Schvartzman

In this tutorial we'll learn how to add the Twitter Bootstrap to the jQueryUI widgets in Asp.Net MVC. The Bootstrap includes many very useful components and also a responsive grid system that scales up to 12 <div>s columns, and adapts itself to the device when size decreases.
Here we'll merge the jQueryUI theme with the Twitter Bootstrap framework, using an outstanding example set up by dipesh.parmar in the following Runnable project.
Bootstrap is the more widely used and more popular CSS3 framework for developing responsive web apps,  making front-end web design very fast and easy.

We'll build a responsive web page using the jQueryUI snippets merged with the Twitter Bootstrap with no effort at all:




The Twitter Bootstrap jQueryUI Merge

First think that's advisable to do is to update the jQuery and the jQueryUI scripts in your MVC application, using NuGet, so that you get the upgraded versions of the scripts :









Then browse to the project build by  dipesh.parmar in the following Runnable project:


If you cannot download and/or see the included files, it's because you are not a member yet, so take 1 minute and log on to Runnable.Copy the HTML markup , and paste it inside the View or in a HTML file:





As you can see, the <HEAD> includes several links to CSS files : all you have to do is import from Runnable those files and put them exactly in the folder as you can see in the Runnable project:



After you set up all the CSS folders & files, take a look at the 5 javascript files we are needing (at the footer of the HTML file):

Therefore copy and arrange all these js files in your application, respecting its folder structure:


That's how your project's file system should appear at the end:


Now, because earlier you upgraded your jQuery & jQueryUI files, you can update the links to use the latest versions:


Browse to your page & you'll see the jQueryUI template made responsive and merged with the Twitter Bootstrap:










That's all!!  In this tutorial we've learned how to add the Twitter Bootstrap to the jQueryUI widgets in Asp.Net MVC.
Happy programming.....

כתב: כרמל שוורצמן















Thursday, June 12, 2014

Step by Step how to position an HTML tag control EXACTLY in the MIDDLE of its container

        By Carmel Shvartzman

In this tutorial we'll learn how to position an HTML tag control EXACTLY in the MIDDLE of its container.
Let's say we have a web page with a button <a> in it, and we want to position it horizontaly EXACTLY in the middle of the web page.
We'll customize the HTML button so that it's located in the MIDDLE of the web page , when at the beginings the button will be showing as follows:




If you want to create a web site like the one in the snapshot, which is using JQuery UI Widgets, like Accordion, Tabs, Portlets, Dialogs, and so on, you'll need to import a JQuery UI Theme, the jquery-ui.js and jquery-ui.css files. (and of course you'll need also a reference to the basic jquery.js file).
You can learn about importing the JQuery UI to your application  in a former tutorial where i explained the task in a complete step by step way.

Let's say the HTML of the button is this:



And the style of the <a> button  is:




Now to position the control EXACTLY in the MIDDLE of the horizontal <DIV> container, add the following code to the CSS button style:

        position:fixed;
        left:50%;
        width:150px;
        margin-left:-75px;
      
We are saying this:
1) position your LEFT border in the MIDDLE (50%) of the container
2) now, MOVE to the left HALF of your WIDTH (in this case, 75px, because the width is 150px)

The CSS button style will be as follows:


This is the CSS for you to COPY-PASTE:

   #btnOpenDialog {
        position:fixed;
        left:50%;
        width:150px;
        margin-left:-75px;
        padding: 5px 5px;
        text-decoration: none;
        font: 900 12px georgia;
        color: #FFF;
    }

And finally the web page will appear with the control EXACTLY in the MIDDLE, as follows:

There is , however, an easy way to horizontally center an HTML element like a <div>, using just CSS3 style, but is not exactly centered in the middle as we learned at this tutorial. You can see it in The HTML5 Club.


That's all!! 
In this tutorial we've learn how to position an HTML tag control EXACTLY in the MIDDLE of its container.  

Happy programming.....


כתב: כרמל שוורצמן




Sunday, June 8, 2014

Step By Step How to open a JQuery UI Dialog from server side

        By Carmel Shvartzman
In this tutorial we'll learn how to open a JQuery UI Dialog from server side, showing at client side a message from the server side. For this tutorial, we'll not use the classic alert() javascript function, but a more sophisticated dialog widget from JQueryUI. 
The jQuery UI is a set of user interface widgets, interactions, and themes built on top of the jQuery JavaScript Library.
We'll customize the JQuery UI Dialog so that it's located in the MIDDLE of the web page, will open in 1000 milliseconds on the screen, and when closed it will disappear during another 1000 milliseconds using the "explode" jquery effect.
We'll want to add to our MVC site the jQuery Dialog , showing as follows:

First, go to the corresponding Controller to add the code to render a message to the browser:
 As you can see, the message will be contained in ViewBag, and will open only when a condition will met : in this case, when a session parameter exists.
Then go to the View, and add the Dialog widget as follows :


Now, we code the following to
1) HIDE the dialog while not necessary
2) DISPLAY the dialog IF the server requires it :


This is the code to copy-paste :

(SERVER SIDE) 
if ((string)Session["status"] == "OPEN_ALERT_WINDOW")
            {
                ViewBag.Alert = true;
                ViewBag.Message = "This is a message sent from the Web Server to client side";
                Session["status"] = null;
            }

(CLIENT SIDE)
        <div >
  <div id="effect" class="ui-widget-content ui-corner-all">  
    <p>
       @ViewBag.Message
    </p>
  </div>
</div>

@{
    <script>
        $("#effect").hide();
    </script>
 
    if (ViewBag.Alert == true)
    {
        <script>
            $("#effect").dialog({
                autoOpen: true,
                title:"Message",
                show: {
                    effect: "blind",
                    duration: 1000
                },
                hide: {
                    effect: "explode",
                    duration: 1000
                }
            });    
     
        </script>
    }  
}


Check whether you load the jquery.js & jquery-ui.js files, containing the necessary functions to call.
And the dialog will finally appears as this :




That's all!! 
In this tutorial we've learn how to open a JQuery UI Dialog from server side, showing at client side a message from the server side. 

Happy programming.....


כתב: כרמל שוורצמן