Telerik Forums
Kendo UI for jQuery Forum
1 answer
1.0K+ views
Hello,

I am using Grids with the pageable option. I would like to keep the selected rows when the page is changed. The standard Grid behavior is, that the selection is not kept. But I already found an approach to store the row selection in the Change event and to restore it in the DataBound event.

global var:
    var selIdsAgentsInService = {};

In change event:
            // store selected rows of AgentsInService grid in selIdsAgentsInService array
            var ids = selIdsAgentsInService[gAgentsInService.dataSource.page()] = [];
            gAgentsInService.select().each(function () {
                dataItem = gAgentsInService.dataItem($(this));
                ids.push($(this).data().uid);
            });

In DataBound event:
        // restore selection
        var selected = $();
        var ids = selIdsAgentsInService[gAgentsInService.dataSource.page()] || [];
        for (var idx = 0, length = ids.length; idx < length; idx++) {
            selected = selected.add(gAgentsInService.table.find("tr[data-uid=" + ids[idx] + "]"));
            gAgentsInService.select(selected);
        }


This is still not exactly doing what I want, and therefore I am looking for a solution to handle the following use cases:

Use case 1 (which is working with my approach):
  1. a grid displays data spread over several pages
  2. rows are selected on page 1
  3. page is changed to another page without selecting any row and back to page 1
  4. the previously selected rows should still be selected
Use case 2:
  1. a grid displays data spread over several pages
  2. rows are selected on page 1
  3. page is changed to another page
  4. a single row is selected without pressing shift or ctrl
  5. page is changed back to page 1
  6. now the previously selected row from page on should be deselected
Use case 3:
  1. a grid displays data spread over several pages
  2. rows are selected on page 1
  3. page is changed to another page
  4. a single row is selected with pressing ctrl (to select an additional row)
  5. page is changed back to page 1
  6. now the previously selected row from page on should still be selected
Anyone having a solution for that? So I would like to support selecting additional rows by pressing ctrl and keeping the selection through all pages. Currently pressing or not pressing ctrl does not make difference in a Change event.

Regards
Sven
Dimo
Telerik team
 answered on 08 Jul 2013
2 answers
324 views
I have a combobox and a list view on a page. When ever an item is selected in the combo box it is suppose to load the listview with items from a table with the selected criteria. No matter what the data is not passed to the read method in the controller

The View
@(Html.Kendo().ComboBox()
        .Name("reportTablesCombo")
        .HtmlAttributes(userControlAttributes)                            
        .DataTextField("Text")
        .DataValueField("Value")                            
        .DataSource(source =>
        {
              source.Read(read =>
        {
                     read.Action("BuildSelectList", "ProgramManager", new { list = "Tables" });
        });
 })
       .Events(e =>
      {
             e.Change("Combo_onChange");
      })
 )     
@(Html.Kendo().ListView(Model)
      .Name("fieldListView")
       .ClientTemplateId("template")               
       .TagName("div")
       .Editable()
      .DataSource(dataSource =>{
                   dataSource.Model(model => model.Id("AdminFieldId"));
                    dataSource.Read(read => read.Action("_Read", "ProgramManager").Data("GetTable"));
                    dataSource.PageSize(10);   
        })
        .Pageable()  
 )
The javascipt

function Combo_onChange(e) {
 
       listdata.dataSource.read();
   }
 
   function GetTable() {
       debugger;
       var table = (reportTablesCombo != null  ? reportTablesCombo.text() : "");
       return table;
   }

the Read method in the controller. I have the debugger going and it returns the proper string but when it is read in the controller the value is ALWAYS null.

What am I doing wrong here?
public ActionResult _Read([DataSourceRequest]DataSourceRequest request, string table)
{
     var results = appDb.AdminFields.Where(t => t.AdminTableName == table);      
     return Json(results.ToDataSourceResult(request));
 }
Paul
Top achievements
Rank 1
 answered on 08 Jul 2013
6 answers
868 views

In MVC3 using VS 2010 I used this all the time no problem. You have an order. You want to be able to view the line items. So you click View in the Custom command of the data grid and it redirects you to a view with the line items for that order. I did this all the time with no issues

Problem: MVC4, VS 2012 and IE10.  Same type of thing. Click the button, it calls the Ajax which  calls the proper method in the controller and passes the parameter in but does not return the View.

I assume its a JQueary issue now. I have been pounding my head against the wall for a good day now and getting nowhere.


The View

@(Html.Kendo().Grid(Model).HtmlAttributes(gridAttributes)
    .Name("grid")
    .Columns(columns =>
    {
        columns.Command(command => { command.Edit().CancelText("Cancel"); command.Custom("Select").Click("showFields");}).Width(150);
        
        
        columns.Bound(c => c.TableName).Width(200);
        columns.Bound(c => c.FriendlyName).Width(200);
        columns.Bound(c => c.SecurityLevel).Width(125);
        columns.Bound(c => c.CanReportOn).Width(125).ClientTemplate("<input type='checkbox' #= CanReportOn ? checked='checked' : '' # value='#=AdminTableId#' class=\"check_row\"/>");
         
 
    })

The Ajax call
BTW, the preventDefault makes no difference. Same result

function showFields(e) {
       // e.preventDefault();
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        var tableName = dataItem.TableName;
              
         
        $.ajax({
            url: '@Url.Action("ShowFields", "ProgramManager")',
             type: 'POST',
              data: { tableName: tableName }
          });
         
    }

The Controller method

public ActionResult ShowFields(string tableName)
{
          var list = appDb.AdminFields.Where(p => p.AdminTableName == tableName);           
          var model = new AdminFieldModel
          {
               Fields = list,
               TableName = tableName
           };
          return View(model);
}
Paul
Top achievements
Rank 1
 answered on 08 Jul 2013
1 answer
136 views
Hello Again =),

I have an issue, I am calculating some fields, and the first time when I load the page with the cache clean, it displays this calculated fields correctly, This is a DateTimePicker inside a Kendo Grid. So when the user click s it we want it to display in an specific format, but after the page has been reloaded or refresh or we go back to the same page,  the format of the date is not respected anymore. Do you have any ideas why is this issue created.

Here is my code"

//New WO to schedule grid
    workOrdersSchedulingDataSource = new kendo.data.DataSource({
        transport: {
            read: {
                // the remote service url
                url: '/sdata/api/dynamic/-/WorkOrders?where=(Status eq \'Unassigned\')&include=Customer,AssignedTo&count=200'
            }
        },
        type: 'sdata',
        serverSorting: true,
        sort: { field: "Priority", dir: "desc" },   
        schema: { data: "$resources",
            model: {
                fields: {$key: { editable: false, defaultValue: "00000000-0000-0000-0000-000000000000" },
                    Priority: { editable: false, nullable: true },
                    Customer: { editable: false, nullable: true },
                    LocationCity: { editable: false, nullable: true },
                    ServiceDate: { editable: true, nullable: true, type: "date" }, // This is the ones I care about
                    ServiceEndDate: { editable: true, nullable: true, type: "date" }, // This is the ones I care about
                    AssignedTo: { editable: true, nullable: true }
                }
            },
            parse: function (data) {
                $.each(data.$resources, function(idx, item) {
                    if (item.AssignedTo == null) {
                        item.AssignedTo = { $key: "", FirstName: "", LastName: ""} ;
                    }
                });
                return data;
            }
        },
        change: function () {
            var count = this.total();
            $("#workOrdersSchedulingCount").text(count);
            if (count == 0) {
                $("#zeroWorkOrdersToScheduling").removeClass("displayNone");
                $("#workOrdersSchedulingTable").addClass("displayNone");
                $("#workOrdersSchedulingFooter").addClass("displayNone");
            } else {
                $("#zeroWorkOrdersToScheduling").addClass("displayNone");
                $("#workOrdersSchedulingTable").removeClass("displayNone");
                $("#workOrdersSchedulingFooter").removeClass("displayNone");
                $("#unassignedBackground").removeClass("displayNone");
                $("#unassignedUnderline").removeClass("displayNone");
            }
        }
    });

var technicianDataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "/sdata/api/dynamic/-/servicesuser?where=Role eq 'Technician'&include=user",
            }
        },
        type: 'sdata',
        schema: { data: "$resources",
            parse: function (data) {
                $.each(data.$resources, function(idx, item) {
                    item['FirstLastName'] = concatFirstLastName(item.User.FirstName, item.User.LastName);
                    item['Id'] = item.User.$key;
                    item['FirstName'] = item.User.FirstName;
                    item['LastName'] = item.User.LastName;
                    //This is the calculated field I cared about

                    item['ServiceDateCalc'] = $.dateUtilities.getUtcDate(item.ServiceDate);      
                    //This one too                          
                    item['ServiceEndDateCalc'] = $.dateUtilities.getUtcDate(item.ServiceEndDate);

                });
                return data;
            }
        }
    });

var schedulingGrid = $("#workOrdersSchedulingTable").kendoGrid({
        dataSource: workOrdersSchedulingDataSource,
        pageable: false,
        sortable: false,
        scrollable: true,
        height: 250,
        dataBound: function () {
            var grid = this;
            $.each(grid.tbody.find('tr'), function () {
                var model = grid.dataItem(this);
                //if Role equals NoRoleAssigned, attach star icon ahead of user name
                if (model.Priority === "Low") {
                    $('[data-uid=' + model.uid + ']' + '>td:first-child').prepend('<span class="staricon">&nbsp;<img src="/Content/images/lowPriority.png" />&nbsp;&nbsp;&nbsp;</span>');
                }
                else if (model.Priority === "Regular") {
                    $('[data-uid=' + model.uid + ']' + '>td:first-child').prepend('<span class="staricon">&nbsp;<img src="/Content/images/regularPriority.png" />&nbsp;&nbsp;&nbsp;</span>');
                }
                else {
                    $('[data-uid=' + model.uid + ']' + '>td:first-child').prepend('<span class="staricon">&nbsp;<img src="/Content/images/criticalPriority.png" />&nbsp;&nbsp;&nbsp;</span>');
                }
            });

            $("table tr").hover(
                function () {
                    $(this).toggleClass("k-state-hover");
                }
            );
        },
        columns: [
            { hidden: true, field: "$key", title: "Key", template: kendo.template($("#tempId").html()) },
            { field: "Priority", title: "Priority", width: "75px"},
            { field: "Customer", title: "Customer", width: "119px", template: "<div style='text-overflow: ellipsis; overflow: hidden; white-space: nowrap;' title='#= Customer.Name #'>#= Customer.Name # </div>"},
            { field: "LocationCity", title: "Location", width: "95px", template: "<div style='text-overflow: ellipsis; overflow: hidden; white-space: nowrap;' title='#= LocationCity #'>#= LocationCity?LocationCity:'N/A' # </div>" },
            { field: "ServiceDate", title: "Start", width: "155px", format: "{0:MM/dd/yyyy hh:mm tt}", template: kendo.template($("#tempStartDate").html()), editor: startDateTimeEditor },
            { field: "ServiceEndDate", title: "End", width: "155px", format: "{0:MM/dd/yyyy hh:mm tt}", template: kendo.template($("#tempEndDate").html()), editor: endDateTimeEditor },
            { field: "AssignedTo", title: "Technician", width: "145px", template: kendo.template($("#tempAssignedTo").html()), editor: assignedToDropDownEditor }
        ], editable: {
            template: null,
            createAt: "bottom"
        }
    });

    function startDateTimeEditor(container, options) {
        $('<input id="serviceDateEditor" data-bind="value:' + options.field + '"/>')
                .appendTo(container)
                .kendoDateTimePicker({
                    dataTextField: "ServiceDateCalc",
                    dataValueField: "ServiceDate"
                });
    }
    
    function endDateTimeEditor(container, options) {
        $('<input id="serviceEndDateEditor" data-bind="value:' + options.field + '"/>')
                .appendTo(container)
                .kendoDateTimePicker({
                    dataTextField: "ServiceEndDateCalc",
                    dataValueField: "ServiceEndDate"
                });
    }

So, it is working for the first time but after that the format gets messy.

Any suggestions? Thank you.

Guillermo Sanchez
Alexander Valchev
Telerik team
 answered on 08 Jul 2013
1 answer
151 views
Alex
Telerik team
 answered on 08 Jul 2013
7 answers
492 views
On change template in code, the repainting of the grid doesn't seem to expand and produce scrollbars to match the new height of the update grid display.

Here's an example. To reproduce the issue, click on the 'Change Template' button:
http://jsfiddle.net/65kWY/20/

PS. Setting scrollable to true (non-virtual) works just fine.

Vladimir Iliev
Telerik team
 answered on 08 Jul 2013
2 answers
110 views
Hello Community,

First of all I will like to thank Telerik for such a great product, it has been a very good experience developing my first Phonegap in conjunction with Keno UI Mobile, nice work ;)

Secondly, I have found a Bug with the state of buttons, to be more precise the class km-state-active gets stucked when a button is pressed, in navbar or content, so the user once have used a button from that view (back-button, actionsheet navbar button, button within content to open a link... and so on), will always get the button as pressed or with the  class km-state-active attached to it, resulting in a confusing and not so great user experience, and it also makes the App "less native" in a sense.

I have found a temporal solution, and will like to get a confirmation (if possible) from the telerik developing team, after trying to track a bit the matter from kendo.mobile.js, I have found that for some reason some of the new events (comparing events from build 2013.1.319) don't seem to work correctly, I will try to explain myself.

I have used an online javascript beautifier (don't know if links from other sites can be included here) and in line 6725 (this is based in the beautifier I have used, it may differ from your numeration) the function attached to the end it's not even triggering:
end: function (e) {
    t(r, e, !1)
}
What this causes is that the buttons can't listen to the end event and the class km-state-active keeps attached to the element causing this behaviour. 

My solution is to always attach this to the functions which are correctly called by the events, which are press and tap (I've done it in both just in case), which call the functions _activate and _release respectively, code from line 6719-6724 (I insist these are the lines I obtain after uncompressing Javascript with the online tool):
press: function (e) {
    r._activate(e)
},
tap: function (e) {
    r._release(e)
},
So I included at the end of the called functions what the end event was supposed to be doing, resulting in these modified versions, lines 6747-6765:
_activate: function (e) {
     var n = document.activeElement,
         i = n ? n.nodeName : "";
     t(this, e, !0), ("INPUT" == i || "TEXTAREA" == i) && n.blur()
     /*INSERT*/
     ;t(r, e, !1);
     /*INSERT*/
 
 },
 _release: function (t) {
     var n = this;
     t.which > 1 || n.trigger(c, {
         target: e(t.target),
         button: n.element
     }) && t.preventDefault()
     /*INSERT*/
     ;t(r, e, !1);
     /*INSERT*/
 },

After that I minify once more the whole javascript (including the Copyright licence on top once more obviously) and ready to go.

I don't know if this is the best approach but it did the trick for me, and it could also shed some light in tracking down this Bug from the last production version of Kendo UI Mobile (if it stills there of course...).

As I said before, thanks for the great product!
Cho-Lung
Top achievements
Rank 1
 answered on 08 Jul 2013
3 answers
190 views
I'm trying to build a grid that displays a set of users, in this example 5 users, and a pie chart that displays those 5 users' licenses and a block of 5 unused licenses for a total of 10 licenses. This jsbin demonstrates the grid and chart. Click the delete button. Notice the grid removes and row but the chart does not reflect the change.

My question is why doesn't the chartDataSource get refreshed when the gridDataSource's data changes?

I found this post and it does provide a workaround but I don't see why the chartDataSource function doesn't get called when model.get('gridDataSource') is used inside of it and clearly the gridDataSource changes.

Here is a jsbin that demonstrates the workaround.

Thanks,
Jon
Alexander Valchev
Telerik team
 answered on 08 Jul 2013
4 answers
388 views
Hi, I'm new to KendoUI, something i not understand is what is the different between

var slider = $('#slider').kendoSlider().data('kendoSlider');

and 

var slider = $('#slider').kendoSlider();

?

what is the .data() method for?

thanks.
CH
Top achievements
Rank 1
 answered on 08 Jul 2013
17 answers
701 views
I'm wanting to changed the default behavior of when you hit enter and it double space to be single spacing when you hit Shift + Enter, but I cannot find out where Shift + Enter is being performed in the source. Also under JavaScript Dependencies there is no list of the required JavaScript files for the editor. Thanks
Alex Gyoshev
Telerik team
 answered on 08 Jul 2013
Narrow your results
Selected tags
Tags
Grid
General Discussions
Charts
Data Source
Scheduler
DropDownList
TreeView
MVVM
Editor
Window
DatePicker
Spreadsheet
Upload
ListView (Mobile)
ComboBox
TabStrip
MultiSelect
AutoComplete
ListView
Menu
Templates
Gantt
Validation
TreeList
Diagram
NumericTextBox
Splitter
PanelBar
Drag and Drop
Application
Map
ToolTip
Calendar
PivotGrid
ScrollView (Mobile)
Toolbar
TabStrip (Mobile)
Slider
Button (Mobile)
Filter
SPA
Drawing API
Drawer (Mobile)
Globalization
LinearGauge
Sortable
ModalView
Hierarchical Data Source
Button
FileManager
MaskedTextBox
View
Form
NavBar
Notification
Switch (Mobile)
SplitView
ListBox
DropDownTree
PDFViewer
Sparkline
ActionSheet
TileLayout
PopOver (Mobile)
TreeMap
ButtonGroup
ColorPicker
Pager
Styling
Chat
MultiColumnComboBox
Dialog
DateRangePicker
Checkbox
Timeline
Drawer
DateInput
ProgressBar
MediaPlayer
ImageEditor
TextBox
OrgChart
Accessibility
Effects
PivotGridV2
Licensing
ScrollView
Switch
TextArea
BulletChart
QRCode
ResponsivePanel
Wizard
CheckBoxGroup
Localization
Barcode
Breadcrumb
Collapsible
MultiViewCalendar
Touch
RadioButton
Stepper
Card
ExpansionPanel
Rating
RadioGroup
Badge
Captcha
Heatmap
AppBar
Loader
Security
TaskBoard
Popover
DockManager
TimePicker
FloatingActionButton
CircularGauge
ColorGradient
ColorPalette
DropDownButton
TimeDurationPicker
ToggleButton
BottomNavigation
Ripple
SkeletonContainer
Avatar
Circular ProgressBar
FlatColorPicker
SplitButton
Signature
Chip
ChipList
VS Code Extension
AIPrompt
PropertyGrid
Sankey
Chart Wizard
OTP Input
SpeechToTextButton
InlineAIPrompt
StockChart
ContextMenu
DateTimePicker
RadialGauge
ArcGauge
AICodingAssistant
SmartPasteButton
PromptBox
SegmentedControl
+? more
Top users last month
Hiba
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Hiba
Top achievements
Rank 1
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Max
Top achievements
Rank 1
Veteran
Iron
Alina
Top achievements
Rank 1
Rakhee
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?