This is a migrated thread and some comments may be shown as answers.

[Solved] How to set a max rows on telerik grid (MVC, Razor)

2 Answers 22 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cameron
Top achievements
Rank 1
Cameron asked on 18 Apr 2013, 02:26 PM
Is there a way to set a maximum of rows on a grid?
For example, i just want to let a customer introduce 15 rows max or a minimum of 1.

Regards,
Cameron CB

2 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 19 Apr 2013, 01:47 PM
Hello Cameron,

This should be possible if you implement the following checks when items are inserted or deleted in the grid data source:
  • When new items are inserted, validate whether the items in the grid source are less than 15. If not, cancel the insert operation and display a user-friendly message to indicate that the action was aborted.
  • When the user attempts to delete a grid item, verify that there is more than one item in the grid. If not, cancel the delete operation and display a user-friendly message to inform the user that the action was aborted.
Try this out and let me know if I am leaving something out.

Regards,
Sebastian
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Cameron
Top achievements
Rank 1
answered on 19 Apr 2013, 02:18 PM
Yes indeed! It works for me. i did this:

.ClientEvents(x => {
    x.OnEdit("CheckRows");
    x.OnDelete("CheckRows"); })
 
<script>
 function CheckRows(e) {   
        var grid = $('#Grid').data('tGrid');
        var button = $("#Grid .t-grid-toolbar .t-grid-add");
        if (grid.insertedDataItems().length - grid.deletedDataItems().length > 15) {
            button.hide();
        }else{
               button.show();
        }
    }
</script>
Tags
General Discussions
Asked by
Cameron
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Cameron
Top achievements
Rank 1
Share this question
or