Contents tagged with jQuery

  • Kendo UI grid – disable row select on command button

    Tags: kendoui, jQuery, web dev

    Kendo UI - The way of HTML5Recently I’ve been working more and more with the Kendo UI components.

    For those that don’t know, Kendo UI is a collection of HTML 5 controls from the wizards at Telerik.

    As with most controls, especially new ones like Kendo.  You find the demos look great and everything seems awesome, but when using in the real world you hit hurdles that are just not covered.

    And that is where I find myself.  I have a grid, with a custom command button, I also have row selection enabled.  I want to run separate commands on row select and the button, but Kendo UI will always execute the row select command (grid change event), even if you are hitting a command button.  I’m sure in some cases that will be fine, but it’s not ideal for me.

    So after a some poking around I found this answer on stackoverflow.

    As mentioned in the above link, this is not supported by the control as yet, so the answer as per that post is to tweak around with the CSS and javascript.  It’s not the most elegant of solutions, but this is javascript, anything is possible … elegance sometimes takes a back seat!

    Command column definition:
    Setting the class to actions being key here!

    selectable: "row",
    change: onRowSelect,
    columns: [
       command: [{
       	name: "Edit", click: function (e) {
            	console.log("edit clicked");
                    var item = this.dataItem($(e.currentTarget).closest("tr"));
    		// Remove row selected class
                    // Do something...
       }], title: " ", width: "50px", attributes: { "class": "actions" }


    Change event handler:
    Taken from stackoverflow

    function onRowSelect(arg) {
                var eventTarget = ( ? $( : $(event.srcElement);
                var isAction = eventTarget.parent().hasClass('actions');
                if (isAction) {
                    console.log("Command button hit");
                // Do what you want for row select


  • jQuery Datatable in MVC … extended.

    Tags: jQuery, MVC, .NET 4.0,

    There are a million plugins for jQuery and when a web forms developer like myself works in MVC making use of them is par-for-the-course!  MVC is the way now, web forms are but a memory!!

    Grids / tables are my focus at the moment.  I don’t want to get in to righting reems of css and html, but it’s not acceptable to simply dump a table on the screen, functionality like sorting, paging, fixed header and perhaps filtering are expected behaviour.  What isn’t always required though is the massive functionality like editing etc you get with many grid plugins out there.

    You potentially spend a long time getting everything hooked together when you just don’t need it.

    That is where the jQuery DataTable plugin comes in.  It doesn’t have editing “out of the box” (you can add other plugins as you require to achieve such functionality).

    What it does though is very nicely format a table (and integrate with jQuery UI) without needing to hook up and Async actions etc. 

    Take a look here…

    I did in the first instance start looking at the Telerik MVC grid control – I’m a fan of Telerik controls and if you are developing an in-house of open source app you get the MVC stuff for free…nice!  Their grid however is far more than I require. 

    Note: Using Telerik MVC controls with your own jQuery and jQuery UI does come with some hurdles, mainly to do with the order in which all your jQuery is executing – I won’t cover that here though – mainly because I don’t have a clear answer on the best way to solve it!

    One nice thing about the dataTable above is how easy it is to extend and there are some nifty examples on the site already…

    I however have a requirement that wasn’t on the site … I need a grid at the bottom of the page that will size automatically to the bottom of the page and be scrollable if required within its own space i.e. everything above the grid didn’t scroll as well.  Now a CSS master may have a great solution to this … I’m not that master and so didn’t! The content above the grid can vary so any kind of fixed positioning is out.

    So I wrote a little extension for the DataTable, hooked that up to the document.ready event and window.resize event.

    Initialising my dataTable ( s )…

    1. $(document).ready(function () {
    2.     var dTable = $(".tdata").dataTable({
    3.         "bPaginate": false,
    4.         "bLengthChange": false,
    5.         "bFilter": true,
    6.         "bSort": true,
    7.         "bInfo": false,
    8.         "bAutoWidth": true,
    9.         "sScrollY": "400px"
    10.     });

    My extension to the API to give me the resizing….

    1. // **********************************************************************
    2. // jQuery dataTable API extension to resize grid and adjust column sizes
    3. //
    4. $.fn.dataTableExt.oApi.fnSetHeightToBottom = function (oSettings) {
    5.     var id =;
    6.     var dt = $("#" + id);
    7.     var top = dt.position().top;
    8.     var winHeight = $(document).height();
    9.     var remain = (winHeight - top) - 83;
    10.     dt.parent().attr("style", "overflow-x: auto; overflow-y: auto; height: " + remain + "px;");
    11.     this.fnAdjustColumnSizing();
    12. }

    This is very much is debug mode, so pretty verbose at the moment – I’ll tidy that up later!

    You can see the last call is a call to an existing method, as the columns are fixed and that normally involves so CSS voodoo, a call to adjust those sizes is required.

    Just above is the style that the dataTable gives the grid wrapper div, I got that from some firebug action and stick in my new height.

    The –83 is to give me the space at the bottom i require for fixed footer!

    Finally I hook that up to the load and window resize.  I’m actually using jQuery UI tabs as well, so I’ve got that in the open event of the tabs.

    1. $(document).ready(function () {
    2.         var oTable;
    3.         $("#tabs").tabs({
    4.             "show": function (event, ui) {
    5.                 oTable = $('div.dataTables_scrollBody>table.tdata', ui.panel).dataTable();
    6.                 if (oTable.length > 0) {
    7.                     oTable.fnSetHeightToBottom();
    8.                 }
    9.             }
    10.         });
    11.         $(window).bind("resize", function () {
    12.             oTable.fnSetHeightToBottom();
    13.         });
    14.     });

    And that all there is too it.  Testament to the wonders of jQuery and the immense community surrounding it – to which I am extremely grateful.

    I’ve also hooked up some custom column filtering on the grid – pretty normal stuff though – you can get what you need for that from their website.  I do hide the out of the box filter input as I wanted column specific, you need filtering turned on when initialising to get it to work and that input come with it!  Tip: fnFilter is the method you want.  With column index as a param – I used data tags to simply that one.


  • Setting jQuery after AJAX partial post back

    Tags: .NET 4.0,, AJAX, jQuery

    OK, so for some reason you have a mega mashup solution with AJAX, jQuery and web forms. 

    Perhaps you are just on the migration from AjaxControlToolkit to the jQuery UI framework – who knows!!

    Anyway, the problem is that when you post back with something like an UpdatePanel, you will find that your nicely setup jQuery stuff, like the datepicker for example will no longer work.

    You may have something like this…

    1. $(document).ready(function () {
    2.     $(".date-edit").datepicker({ dateFormat: "dd/mm/yy", firstDay: 1, showOtherMonths: true, selectOtherMonths: true });
    3. });

    When you’re UpdatePanel post back, you will find that your datepicker has gone.  Bugger!

    Well you need to add this little gem to set it back up again once the UpdatePanel comes back to the page.

    1. var prm = Sys.WebForms.PageRequestManager.getInstance();
    2. prm.add_endRequest(function () {
    3.     $(".date-edit").datepicker({ dateFormat: "dd/mm/yy", firstDay: 1, showOtherMonths: true, selectOtherMonths: true });
    4. });

    Or like me, you would have a javascript function, something like InitPage(); do all your work in there and call that on document.ready and endRequest.

    Your choice…you have the power Smile

    Share this post :


  • 1