Giter Club home page Giter Club logo

how-to-submit-datagrid-model-with-form-values-t590924's Introduction

Form ASP.NET MVC for DevExtreme - How to submit a DataGrid model with form values

The DevExtreme ASP.NET MVC Form can collect information from all hidden inputs and then post it to the Controller. The DataGrid does not initially have a hidden input, and the grid is placed into the form items template. If you assign model values to the grid's dataSource option, the model values are not passed to the server.

This example shows how to create hidden inputs for each DataGrid row at runtime and place the hidden inputs onto the form.

[Run Online]

DevExtreme DataGrid model

Specify the "name" attribute option of the hidden input element. Then, get grid data items from the clickHandler event. Save the data items to the input element in the CreateInputElement function.

<script>
    function CreateInputElement(itemName, itemValue, itemIndex, container) {
        var $input = $("<input/>");

        $input.appendTo(container).attr({ type: "hidden", name: "Orders[" + itemIndex + "]." + itemName }).val(itemValue);
    }
    function clickHandler(e) {
        if (e.validationGroup.validate().isValid) {
            $("#grid").dxDataGrid("instance").getDataSource().load().done(function (items) {
                for (var i = 0; i < items.length; i++) {
                    var item = items[i];
                    for (var property in item) {
                        if (item.hasOwnProperty(property)) {
                            CreateInputElement(property, item[property], i, $("#editEmployee")[0]);
                        }
                    }
                }
                $("#editEmployee").submit();
            })
        }
    }
</script>

Files to Review

Documentation

More Examples

how-to-submit-datagrid-model-with-form-values-t590924's People

Contributors

alexandertemnov avatar dependabot[bot] avatar devexpressexamplebot avatar lexdx avatar onebalaban avatar sergepilipchuk avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.