Problem with getting an entered value

Problem with getting an entered value

NilsJNilsJ Posts: 12Questions: 5Answers: 0

I have a table with article data. The users should fill in quantity and then push on the Buy-button on the current articlerow.
The quantity column is rebndered with the following function: function () {
return "<input type=\"text\" class=\"form-control\">";}
My problem is now that I can't get the entered values. The function cell(rowidx,colidx + 1).data() returns an empty value.

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    Answer ✓

    We need to see actual code to be able to help. There is no context provided above.

  • NilsJNilsJ Posts: 12Questions: 5Answers: 0

    Hope this is what you need (or do you want a json content file to?)

    var bullArticleService = function () {
    var milkbulltable;

    var _init = function () {
    
        $('#bullListNames').on('click', 'a', function () {
            var list = $(this).attr('data-list');
            _loadArticles(list);
        });
    
        $('#btnsearchinbreed').on('click', function () {
            var searchStr = $('#dpsearchtext').val();
            var breed = $('#breedNr').text();
            _searchInbreed(breed, searchStr);
        });
    
        milkbulltable = $('[vxa-page="bullList.table"] [vxa-role="milkbullTable"]').DataTable({
            lengthChange: false,
            fixedHeader: true,
            data: {},
            rowId: "articleName",
            //order: [1, "desc"],
            autoWidth: false,
            pageLength: 20,
            ordering: false,
            language: {
                search: "Sök i listan :  ",
                searchPlaceholder: "",
                infoFiltered: "",
                lengthMenu: "Visa _MENU_ rader per sida",
                info: "Visar _START_ till _END_ (av totalt _TOTAL_ resurser)",
                sZeroRecords: "Hittade inga matchande resultat",
                sInfoEmpty: "",
                paginate: {
                    first: "",
                    previous: "",
                    next: "",
                    last: ""
                }
            },
            columnDefs: [
                {
                    "targets": [0],
                    "data": "articleName",
                    "width": 300,
    
                    "render": function (data, type, full) {
                        return "<a href='" + full.uRLRef + "' target='_blank'>" + data + "</a>";
    
                    }
                },
                {
                    "targets": [1],
                    "width": 100,
                    "data": "nTMString"
    
                },
                {
                    "width": 100,
                    "targets": [2],
                    "data": "price"
                },
                {
                    "targets": [3],
                    "data": null,
                    "className": "btn-buy",
                    "width": 100,
                    "render": function () {
                        return "<button class=\"btn btn-success\" type=\"button\"><i class=\"fa fa-shopping-cart\" aria-hidden=\"true\"></i> Köp</button>";
                    }
                },
                {
                    "targets": [4],
                    "data": null,
                     "width": 100,
                    "render": function () {
                        return "<input type=\"text\" id=\"edit-quantity\"  class=\"form-control\">";
                    }
                },
                {
                    "targets": [5],
                    "width": 250,
                    "data": "comment"
                },
                {
                    "targets": [6],
                    "width": 50,
                    "visible": false,
                    "data": "artNr"
                }
            ]
        });
    
        milkbulltable.on('click', 'td.btn-buy', function () {
            var row = milkbulltable.row($(this).parents('tr'));
           var data = row.data();
    
            var colindex = milkbulltable.column(this).index();
            var rowidx = milkbulltable.row(this).index(); 
    
            var quantity = cell(rowidx, colindex + 1).data(); 
            //This does not work, will only return a empty or null reference   
    
            shoppinCartService.addItemToCart(data.artNr, data.articleName, data.price, **_quantity_**);
            //}
        });
    
    };
    
    var _loadArticles = function (listId) {
    
        milkbulltable.clear().draw();
        // resa söktexten
        $('[vxa-page="bullList.table"]').fadeIn('fast');
    
    
        ajaxService.ajaxGet('/BullList/BullArticlesByListid/' + listId, function (response) {
            milkbulltable.rows.add(
                $.map(response.data, function (value, index) {
                    return {
                        'articleName': value.articleName,
                        'nTMString': value.ntmString,
                        'price': value.price,
                        'uRLRef': value.urlRef,
                        'comment': value.comment,
                        'artNr': value.artNr //,
                        //'antal': ""
                    };
                })
            ).draw();
        });
    };
    
    var _searchInbreed = function (breed, searchstr) {
    
        milkbulltable.clear().draw();
        //
        //$('[vxa-page="bullList.table"]').fadeIn('fast');
    
        ajaxService.ajaxGet('/Article/SearchBullByBreed/' + breed + '/' + searchstr, 
        function (response) {
            milkbulltable.rows.add(
                $.map(response.data, function (value, index) {
                    return {
                        'articleName': value.articleName,
                        'nTMString': value.ntmString,
                        'price': value.price,
                        'uRLRef': value.urlRef,
                        'comment': value.comment,
                        'artNr': value.artNr
                    };
                })
            ).draw();
        });
    };
    
    
    
    
    
    return {
        init: _init,
        loadArticles: _loadArticles,
        searchInbreed: _searchInbreed
    };
    

    }();

This discussion has been closed.