Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

Tuesday, November 3, 2015

An unknown function with name 'substringof' was found.

While doing some client script have faced the issue.





























  $.each(searchWords, function (key, word) {
                            if (key) filterWords += "%20and%20";
                            // double up any single quotes
                            word = word.replace(/'/g, "''");
                            // url escape word
                            word = encodeURIComponent(word);
                            filterWords += "contains(ProductName,'" + word + "')";
                        });

                        // create base portion of the URI
                        var queryUri = serviceUri + "Products?" +
                          "$select=ProductID,ProductName&" +
                          "$top=100&" +
                          "$filter=" + filterWords;
                        // configure datajs to allow cross domain callbacks using JSONP
                        OData.defaultHttpClient.enableJsonpCallback = true;
                        // run query
                        OData.read(queryUri, function (queryResponse) {
                            // for each result, add to list
                            $.each(queryResponse.value.results, function (o) {
                                $("#queryResultsList").append("

  • " + this.ProductName + "
  • ");


    Wednesday, April 8, 2015

    Hide or show list form fields in SharePoint using jQuery

    David Lozzi has written a jquery library which is useful our daily development activites.
    http://davidlozzi.com/2014/01/14/sharepoint-2013-script-hide-or-disable-your-fields
    ExecuteOrDelayUntilScriptLoaded(function(){
      Lozzi.Fields.disableWithAllowance("Employee Name",["LeaveEntryAuthorization"]);

      },"sp.js");
    sp.js should load before execute the code.

    Wednesday, December 31, 2014

    JQuery-Plugin, JQGrid

    JQ Grid is excellent alternative of the ASP.NET GridVIew.
    http://www.trirand.net/demo/aspnet/webforms/jqgrid/

    title = "My Software Assets";
            var grid = $("#softwaregrid");
            $("#softwaregrid").jqGrid(
                    {
                        prmNames: { search: "isSearch", nd: null, rows: "numRows", page: "page", sort: "sortField", order: "sortOrder" },
                        postData: { searchString: '', searchField: '', searchOper: '', hiearchy: JSON.stringify(locselection) },
                        datatype: function (postdata) {
                            if (locselection != "MyAssets")
                            {
                                GetSelections();
                            }
                            //alert(JSON.stringify(locselection));
                            $('#softwaregrid').setGridParam({ postData: { hiearchy: JSON.stringify(locselection)} });
                            mtype: "GET", $.ajax({ url: L_Menu_BaseUrl + "/_layouts/XXX/Pages/SwassetService.aspx/GetReports1SoftwareData",
                                type: "POST",
                                async: false,
                                contentType: "application/json; charset=utf-8",
                                data: JSON.stringify(postdata),
                                dataType: "json",
                                success: function (data, st) {

                                    if (st == "success")
                                    {
                                        var grid = jQuery("#softwaregrid")[0];
                                        grid.addJSONData(JSON.parse(data.d));
                                    }
                                },
                                error: function () { alert("Error with AJAX callback"); }
                            });
                        },
                        jsonReader: { root: "rows", page: "page", total: "totalpages", records: "totalrecords", cell: "cell", id: "id", userdata: "userdata", repeatitems: true },                
                        colNames: ['Select', 'ID', 'Title', 'Description', 'Category', 'Terminal', 'Region', 'Supplier'],                 
                        colModel: [
                        { name: 'Select', index: 'id', search: false, hidden: true },
                        { name: 'ID', index: 'id', search: false, hidden: true },
                                                                                    { name: 'Title',width: '140px',index: 'a.SoftwareTitle', searchoptions: { sopt: ['cn'] }, hidden: false },
                       
                                                                                    {name: 'Description', width: '290px', index: 'a.Description', search: false },
                                                                                    {name: 'Category', width: '80px', index: 'b.Name', searchoptions: { sopt: ['cn']} },
                                                                                    { name: 'Terminal', width: '215px', index: 'a.Terminal', search: false },
                                                                                    { name: 'Region', width: '50px', index: 'a.Region', search: false },
                                                                                    { name: 'Supplier', width: '115px', index: 'e.Name', search: false },
                                                                                    //{ name: 'Delete', width: '50px', index: 'Delete', search: false }//Naveed SW
                                                                                    ],

                        rowNum: 5,
                        rowList: [5, 10, 30,50,100],//Naveed SW
                        //width: '800px',
                        height: '300px',
                        //scrollOffset: 0,                          
                        autowidth: true,
                                    multiselect: true,
                        //autoheight:true,
                        shrinkToFit: false,
                        forceFit: true,
                        pager: jQuery("#softwarePager"),
                        sortname: "a.ID",
                        sortorder: "asc",
                                    onSelectRow: function (id, status) {
                                   
                                                    if (!status)
                                                    {
                                                                    if ($("#jqg_softwaregrid_" + id)[0].checked)                       //Naveed SW   
                                                                    {
                                                                                    $("#softwaregrid").jqGrid('setSelection', id,false);
                                                                    }
                                                    }
                                    },                            
                                    del : {
                                                                    caption: "ff",
                                                                    msg: "Delete  record(s)?",
                                                                    bSubmit: "Delete",
                                                                    bCancel: "Cancel"
                                                    },                                            
                        ondblClickRow: function (rowid) {
                            var win = window.open("createasset.aspx?assetid=" + rowid, '_blank');
                            win.focus();
                        },
                        viewrecords: true, caption: title
                    }).jqGrid('navGrid', "#softwarePager", { edit: false, add: false, del: true, search: true, refresh: true, closeAfterSearch: true, searchtext: "Filter", refreshtext: "Refresh",deltext:"Delete" , deltitle: "Delete selected row(s)"},{},{},
                                                    {
                  url: '#',
                  onclickSubmit: function (postdata) {
                                                                    DeleteSoftwares();
                                                                    return {};
                 },
                                                     reloadAfterSubmit:true,
                                                     beforeShowForm: function(form)
                                                                    {
                                                                      $("#delmodsoftwaregrid")[0].style.left="581px"
                                                                      $("#delmodsoftwaregrid")[0].style.top="220px"
                                                                    }
                                                    }
                    //            ).hideCol('cb');//Naveed SW
                                    );
                                    $('#softwaregrid').trigger( 'reloadGrid');
        }
    function DeleteSoftwares()
    {
    var swselection = [];
    $(".cbox:checkbox:checked").each(function () {/
            swselection.push(this.name.substr(this.name.lastIndexOf("_")+1, this.name.length-1));
        })
    var url=location.protocol + "//" + location.host + L_Menu_BaseUrl;

    $.ajax(
                    {
                        type: "POST",
                        url:L_Menu_BaseUrl + "/_layouts/XXX/Pages/SwassetService.aspx/DeleteSoftwares",
                        data: "{'softwares' : '" + JSON.stringify(swselection)+ "','url' : '" + url + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        async: true,
                        cache: false,
                        success: function (msg) {

    }
    }
    );
    }

    Monday, April 2, 2012

    Icon Rollover using jQuery in SharePoint 2010

    1)Add a CQWP on the sharepoint page.
    2)Open SPD2010
    3)Edit it with the following code...

    $(document).ready(function() {
    $("img.rollover").hover(
    function() { this.src = this.src.replace("_UP", "_OVER");});
    $("img.rollover").mouseout(
    function() { this.src = this.src.replace("_OVER", "_UP");});

    });

    Save it and refresh the page on the browser.
    UseFul link:
    http://kaidez.com/tutorial-simple-effective-jquery-image-rollover/

    Thursday, March 8, 2012

    Hide fields in the list form using jQuery

    The rule would be as follow:
    1. Show the row of “Others” only if [Issue Type] = “Others”
    2. Otherwise, hide the whole row of “Others”.
    Solution:
    Add a CQWP on the list:

    Open the SPD2010
    Update the CQWP with the below statements

    Ticket1 and Ticket2 are the classes of the controls

    Save the updates in SPD2010 and then refresh the page on the browser.