jQWidgets Forums

jQuery UI Widgets Forums Grid In Grid want to add file upload

This topic contains 22 replies, has 5 voices, and was last updated by  stvhui 11 years, 2 months ago.

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
  • In Grid want to add file upload #46315

    sachinhere
    Participant

    Hi,

    I want add file upload option grid…I have added input file tag and try to render it.. It is displaying browse option but
    when click or edit on other cell or i have added any new row uploaded file info is get cleared…

    I am trying to resolve last to 5-6 days not yet resolve…
    I want add file upload option… add new row can also upload file. How can i do it?

    <!DOCTYPE html>
    <html lang=”en”>
    <head>
    <title id=’Description’>In this sample is illustrated how to create a Grid with column which displays values from foreign data source. The DropDownList editor associated to the column is populated from the foreign data source.</title>
    <link rel=”stylesheet” href=”./contacts/jqwidgets/styles/jqx.base.css” type=”text/css” />
    <script type=”text/javascript” src=”./contacts/scripts/jquery-1.10.2.min.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxcore.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxdata.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxbuttons.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxscrollbar.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxmenu.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.selection.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.edit.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxlistbox.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.edit.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxdropdownlist.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxcombobox.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxpanel.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxinput.js”></script>
    <script type=”text/javascript”>
    $(document).ready(function () {
    var data = new Array();
    var source_name =
    [
    ‘Source Name1’
    ];
    var data_type =
    [
    ‘DataType’
    ];
    var mainsite =
    [
    ‘www.testsite.com’
    ];
    var contact_name =
    [
    ‘Contact Name’
    ];
    var phone_number =
    [
    ‘Phone Number’
    ];
    var email =
    [
    ‘test@test.com’
    ];
    var generalnotes =
    [
    ‘Enter Notes here’
    ];
    // prepare the data
    var data1 = {};
    var theme = ‘classic’;
    var generaterow = function (i) {

    var row = {};
    row[“SourceName”] = source_name[i];
    row[“DataType”] = data_type[i];
    row[“mainSite”] = mainsite[i];
    row[“ContactName”] = contact_name[i];
    row[“Phone”] =phone_number[i];
    row[“Email”] =email[i];
    row[“GeneralNotes”] =generalnotes[i];
    return row;
    }
    for (var i = 0; i < source_name.length; i++) {
    var row = generaterow(i);
    data1[i] = row;
    }

    var theme = ”;
    var datasources = [
    <?php
    include ‘config.php’;

    $rs = mysql_query(‘SELECT id,fullname FROM T_datasources’);

    while($row = mysql_fetch_object($rs)){
    ?>

    {‘value’:<?php echo $row->id?>,’label’:'<?php echo $row->fullname?>’},

    <?php
    }
    ?>
    ];

    var countriesSource =
    {
    datatype: “array”,
    datafields: [
    { name: ‘label’, type: ‘string’ },
    { name: ‘value’, type: ‘string’ }
    ],
    localdata: datasources
    };
    var countriesAdapter = new $.jqx.dataAdapter(countriesSource, {
    autoBind: true
    });
    var demodata = [
    { dataCode: “1”,SourceName:’Source Name’,datatype:’Please Choose’,mainSite:’http://www.test.com’,ContactName:’ContactName’,Phone:’1234567890′,Email:’test@test.com’,GeneralNotes:'<input type=”file” name=”a” readonly onchange=”onFileSelected(event)”/>’ }
    ];
    var demodata1 = [
    { dataCode: “1”,SourceName:’Source Name’,datatype:’Please Choose’,mainSite:’http://www.test.com’,ContactName:’ContactName’,Phone:’1234567890′,Email:’test@test.com’,GeneralNotes:'<input type=”file” name=”a[]” readonly onchange=”onFileSelected(event)” />’ }
    ];

    // prepare the data
    var gridSource =
    {
    datatype: “array”,
    localdata: {} ,
    datafields: [
    // name – determines the field’s name.
    // value – the field’s value in the data source.
    // values – specifies the field’s values.
    // values.source – specifies the foreign source. The expected value is an array.
    // values.value – specifies the field’s value in the foreign source.
    // values.name – specifies the field’s name in the foreign source.
    // When the adapter is loaded, each record will have a field called “Country”. The “Country” for each record comes from the countriesAdapter where the record’s “dataCode” from gridAdapter matches to the “value” from countriesAdapter.
    { name: ‘SourceName’, type: ‘string’},
    { name: ‘datatype’, value: ‘dataCode’, values: { source: countriesAdapter.records, value: ‘value’, name: ‘label’ } },
    { name: ‘dataCode’, type: ‘string’},
    { name: ‘mainSite’, type: ‘string’},
    { name: ‘ContactName’, type: ‘string’},
    { name: ‘Phone’, type: ‘string’},
    { name: ‘Email’, type: ‘string’},
    { name: ‘GeneralNotes’, type: ‘html’}

    ], addrow: function (rowid, rowdata, position, commit) {
    // synchronize with the server – send insert command
    // call commit with parameter true if the synchronization with the server is successful
    //and with parameter false if the synchronization failed.
    // you can pass additional argument to the commit callback which represents the new ID if it is generated from a DB.
    commit(true);
    },
    };
    var uploadrenderer = function () { return ‘<input class=”FileColumn4″ name=”FileColumn4″ type=”file” />’; }
    var gridAdapter = new $.jqx.dataAdapter(gridSource);
    $(“#jqxgrid”).jqxGrid(
    {
    width: 1200,
    source: gridAdapter,
    theme: theme,
    autoheight: true,
    editable: true,
    columns: [
    { text: ‘Source Name’, editable: true, datafield: ‘SourceName’, width: 200,valign: ‘top’ },

    {
    text: ‘Data Type’, datafield: ‘dataCode’, displayfield: ‘datatype’, columntype: ‘dropdownlist’,
    createeditor: function (row, value, editor) {
    editor.jqxDropDownList({ source: countriesAdapter, displayMember: ‘label’, valueMember: ‘value’ });
    }

    },
    { text: ‘main Site’, editable: true, datafield: ‘mainSite’, width:200 },
    { text: ‘Contact Name’, editable: true, datafield: ‘ContactName’, width: 200 },
    { text: ‘Phone’,editable: true, datafield: ‘Phone’, type: ‘html’},
    { text: ‘Email’,editable: true, datafield: ‘Email’, type: ‘html’},
    { text: ‘General Note’,editable: false, datafield: ‘GeneralNotes’,width: 250 }

    ]
    });

    $(“#addrowbutton”).jqxButton();
    // create new row.
    var aa=0;
    $(“#addrowbutton”).on(‘click’, function () {
    $(“input[name^=a]”).each(function() {
    //alert($(this).attr(‘src’));
    });
    var id = $(“#jqxgrid”).jqxGrid(‘getdatainformation’).rowscount;
    $(“#jqxgrid”).jqxGrid(‘addrow’, id, {});
    $(“#jqxgrid”).jqxGrid(‘setcellvalue’, aa, ‘GeneralNotes’, ‘<input type=”file” name=”a’+aa+'” readonly />’);
    aa++;
    });
    var countries = new Array(“Afghanistan”, “Albania”, “Algeria”, “Andorra”, “Angola”, “Antarctica”, “Antigua and Barbuda”, “Argentina”, “Armenia”, “Australia”, “Austria”, “Azerbaijan”, “Bahamas”, “Bahrain”, “Bangladesh”, “Barbados”, “Belarus”, “Belgium”, “Belize”, “Benin”, “Bermuda”, “Bhutan”, “Bolivia”, “Bosnia and Herzegovina”, “Botswana”, “Brazil”, “Brunei”, “Bulgaria”, “Burkina Faso”, “Burma”, “Burundi”, “Cambodia”, “Cameroon”, “Canada”, “Cape Verde”, “Central African Republic”, “Chad”, “Chile”, “China”, “Colombia”, “Comoros”, “Congo, Democratic Republic”, “Congo, Republic of the”, “Costa Rica”, “Cote d’Ivoire”, “Croatia”, “Cuba”, “Cyprus”, “Czech Republic”, “Denmark”, “Djibouti”, “Dominica”, “Dominican Republic”, “East Timor”, “Ecuador”, “Egypt”, “El Salvador”, “Equatorial Guinea”, “Eritrea”, “Estonia”, “Ethiopia”, “Fiji”, “Finland”, “France”, “Gabon”, “Gambia”, “Georgia”, “Germany”, “Ghana”, “Greece”, “Greenland”, “Grenada”, “Guatemala”, “Guinea”, “Guinea-Bissau”, “Guyana”, “Haiti”, “Honduras”, “Hong Kong”, “Hungary”, “Iceland”, “India”, “Indonesia”, “Iran”, “Iraq”, “Ireland”, “Israel”, “Italy”, “Jamaica”, “Japan”, “Jordan”, “Kazakhstan”, “Kenya”, “Kiribati”, “Korea, North”, “Korea, South”, “Kuwait”, “Kyrgyzstan”, “Laos”, “Latvia”, “Lebanon”, “Lesotho”, “Liberia”, “Libya”, “Liechtenstein”, “Lithuania”, “Luxembourg”, “Macedonia”, “Madagascar”, “Malawi”, “Malaysia”, “Maldives”, “Mali”, “Malta”, “Marshall Islands”, “Mauritania”, “Mauritius”, “Mexico”, “Micronesia”, “Moldova”, “Mongolia”, “Morocco”, “Monaco”, “Mozambique”, “Namibia”, “Nauru”, “Nepal”, “Netherlands”, “New Zealand”, “Nicaragua”, “Niger”, “Nigeria”, “Norway”, “Oman”, “Pakistan”, “Panama”, “Papua New Guinea”, “Paraguay”, “Peru”, “Philippines”, “Poland”, “Portugal”, “Qatar”, “Romania”, “Russia”, “Rwanda”, “Samoa”, “San Marino”, ” Sao Tome”, “Saudi Arabia”, “Senegal”, “Serbia and Montenegro”, “Seychelles”, “Sierra Leone”, “Singapore”, “Slovakia”, “Slovenia”, “Solomon Islands”, “Somalia”, “South Africa”, “Spain”, “Sri Lanka”, “Sudan”, “Suriname”, “Swaziland”, “Sweden”, “Switzerland”, “Syria”, “Taiwan”, “Tajikistan”, “Tanzania”, “Thailand”, “Togo”, “Tonga”, “Trinidad and Tobago”, “Tunisia”, “Turkey”, “Turkmenistan”, “Uganda”, “Ukraine”, “United Arab Emirates”, “United Kingdom”, “United States”, “Uruguay”, “Uzbekistan”, “Vanuatu”, “Venezuela”, “Vietnam”, “Yemen”, “Zambia”, “Zimbabwe”);
    $(“input[name^=a]”).jqxInput({placeHolder: “Enter a Country”, height: 25, width: 200, minLength: 1, theme: theme, source: countries });

    });
    </script>
    </head>
    <body class=’default’>
    <form action=”” method=”post”
    enctype=”multipart/form-data”>
    <div id=’jqxWidget’>
    <div id=”jqxgrid”>
    </div>
    <div style=”font-size: 13px; “margin-top: 20px; font-family: Verdana, Geneva, ‘DejaVu Sans’, sans-serif;” id=”eventLog”></div>
    </div>
    <div style=”margin-left: 10px; float: left;”>
    <div>
    <input id=”addrowbutton” type=”button” value=”Add New Row” />
    </div>
    </div>

    <input type=”submit” name=”123″ value=”Submit”>
    </form>
    </body>
    </html>

    In Grid want to add file upload #46325

    Dimitar
    Participant

    Hello sachinhere,

    Please format your code by selecting it and clicking the code button in the new post toolbar and then re-post it.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    In Grid want to add file upload #46329

    sachinhere
    Participant

    <!DOCTYPE html>
    <html lang=”en”>
    <head>
    <title id=’Description’>In this sample is illustrated how to create a Grid with column which displays values from foreign data source. The DropDownList editor associated to the column is populated from the foreign data source.</title>
    <link rel=”stylesheet” href=”./contacts/jqwidgets/styles/jqx.base.css” type=”text/css” />
    <script type=”text/javascript” src=”./contacts/scripts/jquery-1.10.2.min.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxcore.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxdata.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxbuttons.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxscrollbar.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxmenu.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.selection.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.edit.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxlistbox.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxgrid.edit.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxdropdownlist.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxcombobox.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxpanel.js”></script>
    <script type=”text/javascript” src=”./contacts/jqwidgets/jqxinput.js”></script>
    <script type=”text/javascript”>
    $(document).ready(function () {
    var data = new Array();
    var data1 = {};
    var theme = ”;
    var datasources = [{id:1,value:’a’},{id:1,value:’b’},{id:1,value:’c’}];
    var dataSource =
    {
    datatype: “array”,
    datafields: [ { name: ‘label’, type: ‘string’ },{ name: ‘value’, type: ‘string’ }],
    localdata: datasources
    };
    var dataAdapter = new $.jqx.dataAdapter(dataSource, {autoBind: true});
    var demodata = [{ dataCode: “1”,SourceName:’Source Name’,datatype:’Please Choose’,mainSite:’http://www.test.com’,ContactName:’ContactName’,Phone:’1234567890′,Email:’test@test.com’,GeneralNotes:'<input type=”file” name=”a” readonly onchange=”onFileSelected(event)”/>’ }];
    // prepare the data
    var gridSource =
    {
    datatype: “array”,
    localdata: {} ,
    datafields: [
    { name: ‘SourceName’, type: ‘string’},
    { name: ‘datatype’, value: ‘dataCode’, values: { source: dataAdapter.records, value: ‘value’, name: ‘label’ } },
    { name: ‘dataCode’, type: ‘string’},
    { name: ‘mainSite’, type: ‘string’},
    { name: ‘ContactName’, type: ‘string’},
    { name: ‘Phone’, type: ‘string’},
    { name: ‘Email’, type: ‘string’},
    { name: ‘GeneralNotes’, type: ‘html’}
    ],
    addrow: function (rowid, rowdata, position, commit) {
    commit(true);
    },
    };
    var uploadrenderer = function () { return ‘<input class=”FileColumn4″ name=”FileColumn4″ type=”file” />’; }
    var gridAdapter = new $.jqx.dataAdapter(gridSource);
    $(“#jqxgrid”).jqxGrid(
    {
    width: 1200,
    source: gridAdapter,
    theme: theme,
    autoheight: true,
    editable: true,
    columns: [
    { text: ‘Source Name’, editable: true, datafield: ‘SourceName’, width: 200,valign: ‘top’ },
    {
    text: ‘Data Type’, datafield: ‘dataCode’, displayfield: ‘datatype’, columntype: ‘dropdownlist’,
    createeditor: function (row, value, editor) {
    editor.jqxDropDownList({ source: dataAdapter, displayMember: ‘label’, valueMember: ‘value’ });
    }
    },
    { text: ‘main Site’, editable: true, datafield: ‘mainSite’, width:200 },
    { text: ‘Contact Name’, editable: true, datafield: ‘ContactName’, width: 200 },
    { text: ‘Phone’,editable: true, datafield: ‘Phone’, type: ‘html’},
    { text: ‘Email’,editable: true, datafield: ‘Email’, type: ‘html’},
    { text: ‘General Note’,editable: false, datafield: ‘GeneralNotes’,width: 250 }

    ]
    });

    $(“#addrowbutton”).jqxButton();
    // create new row.
    var aa=0;
    $(“#addrowbutton”).on(‘click’, function () {
    $(“input[name^=a]”).each(function() {
    //alert($(this).attr(‘src’));
    });
    var id = $(“#jqxgrid”).jqxGrid(‘getdatainformation’).rowscount;
    $(“#jqxgrid”).jqxGrid(‘addrow’, id, {});
    $(“#jqxgrid”).jqxGrid(‘setcellvalue’, aa, ‘GeneralNotes’, ‘<input type=”file” name=”a’+aa+'” readonly />’);
    aa++;
    });
    //$(“input[name^=a]”).jqxInput({placeHolder: “Enter a Country”, height: 25, width: 200, minLength: 1, theme: theme, source: data });

    });
    </script>
    </head>
    <body class=’default’>
    <div id=’jqxWidget’>
    <div id=”jqxgrid”>
    </div>
    <div style=”font-size: 13px; “margin-top: 20px; font-family: Verdana, Geneva, ‘DejaVu Sans’, sans-serif;” id=”eventLog”></div>
    </div>
    <div style=”margin-left: 10px; float: left;”>
    <div>
    <input id=”addrowbutton” type=”button” value=”Add New Row” />
    </div>
    </div>
    </form>
    </body>
    </html>

    In Grid want to add file upload #46331

    sachinhere
    Participant

    Can please give code like i can upload image through grid. When i will add new row. Value in input type file is get cleared… I want upload image button on each row… How can i edit that? this thing i want to know.

    In Grid want to add file upload #46385

    Dimitar
    Participant

    Hi sachinhere,

    I assume you are using uploadrenderer as cellsrenderer.

    Unfortunately, this input clearing behaviour cannot be disabled. When you edit a cell or add a new row, the grid is re-rendered, and the values of the file inputs are lost.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    In Grid want to add file upload #46402

    sachinhere
    Participant

    My main issues is How can i add input file button in grid… Is there any way i am asking…otherwise i will move to another grid solution.In my site i have used only your grid… that why i am asking your reply is very late. can you provide me good example urgenty…

    In Grid want to add file upload #46403

    Dimitar
    Participant

    Hello sachinhere,

    Here is an example, based on the demo Custom Column Editor. When you enter the edit mode of a cell from the Upload column, you will be able to select files to upload without losing the selection.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdata.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxmenu.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxinput.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxslider.js"></script>
        <script type="text/javascript" src="../../scripts/gettheme.js"></script>
        <script type="text/javascript" src="generatedata.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var theme = "";
    
                // prepare the data
                var data = generatedata(200);
    
                var source =
                {
                    localdata: data,
                    datatype: "array",
                    updaterow: function (rowid, rowdata, commit) {
                        // synchronize with the server - send update command
                        // call commit with parameter true if the synchronization with the server is successful 
                        // and with parameter false if the synchronization failder.
                        commit(true);
                    },
                    datafields:
                    [
                        { name: 'firstname', type: 'string' },
                        { name: 'lastname', type: 'string' },
                        { name: 'productname', type: 'string' },
                        { name: 'available', type: 'bool' },
                        { name: 'upload', type: 'string' },
                        { name: 'price', type: 'number' },
                        { name: 'date', type: 'date' }
                    ]
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                var getEditorDataAdapter = function (datafield) {
                    var source =
                     {
                         localdata: data,
                         datatype: "array",
                         datafields:
                           [
                               { name: 'firstname', type: 'string' },
                               { name: 'lastname', type: 'string' },
                               { name: 'productname', type: 'string' },
                               { name: 'available', type: 'bool' },
                               { name: 'upload', type: 'string' },
                               { name: 'price', type: 'number' },
                               { name: 'date', type: 'date' }
                           ]
                     };
                    var dataAdapter = new $.jqx.dataAdapter(source, { uniqueDataFields: [datafield] });
                    return dataAdapter;
                }
    
                // initialize jqxGrid
                $("#jqxgrid").jqxGrid(
                {
                    width: 685,
                    source: dataAdapter,
                    editable: true,
                    theme: theme,
                    selectionmode: 'singlecell',
                    columns: [
                      {
                          text: 'First Name', columntype: 'template', datafield: 'firstname', width: 80, createeditor: function (row, cellvalue, editor, cellText, width, height) {
                              // construct the editor.
                              var inputElement = $("<input/>").prependTo(editor);
                              inputElement.jqxInput({ source: getEditorDataAdapter('firstname'), displayMember: "firstname", width: width, height: height, theme: theme });
                          },
                          initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
                              // set the editor's current value. The callback is called each time the editor is displayed.
                              var inputField = editor.find('input');
                              if (pressedkey) {
                                  inputField.val(pressedkey);
                                  inputField.jqxInput('selectLast');
                              }
                              else {
                                  inputField.val(cellvalue);
                                  inputField.jqxInput('selectAll');
                              }
                          },
                          geteditorvalue: function (row, cellvalue, editor) {
                              // return the editor's value.
                              return editor.find('input').val();
                          }
                      },
                      {
                          text: 'Last Name', datafield: 'lastname', columntype: 'template', width: 80, createeditor: function (row, cellvalue, editor, cellText, width, height) {
                              // construct the editor.
                              var inputElement = $("<input/>").prependTo(editor);
                              inputElement.jqxInput({ source: getEditorDataAdapter('lastname'), displayMember: "lastname", width: width, height: height, theme: theme });
                          },
                          initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
                              // set the editor's current value. The callback is called each time the editor is displayed.
                              var inputField = editor.find('input');
                              if (pressedkey) {
                                  inputField.val(pressedkey);
                                  inputField.jqxInput('selectLast');
                              }
                              else {
                                  inputField.val(cellvalue);
                                  inputField.jqxInput('selectAll');
                              }
                          },
                          geteditorvalue: function (row, cellvalue, editor) {
                              // return the editor's value.
                              return editor.find('input').val();
                          }
                      },
                      {
                          text: 'Products', columntype: 'template', datafield: 'productname',
                          createeditor: function (row, cellvalue, editor, cellText, width, height) {
                              // construct the editor. 
                              editor.jqxDropDownList({
                                  checkboxes: true, source: getEditorDataAdapter('productname'), displayMember: 'productname', valueMember: 'productname', width: width, height: height, theme: theme,
                                  selectionRenderer: function () {
                                      return "Please Choose:";
                                  }
                              });
                          },
                          initeditor: function (row, cellvalue, editor, celltext, pressedkey) {
                              // set the editor's current value. The callback is called each time the editor is displayed.
                              var items = editor.jqxDropDownList('getItems');
                              editor.jqxDropDownList('uncheckAll');
                              var values = cellvalue.split(/,\s*/);
                              for (var j = 0; j < values.length; j++) {
                                  for (var i = 0; i < items.length; i++) {
                                      if (items[i].label === values[j]) {
                                          editor.jqxDropDownList('checkIndex', i);
                                      }
                                  }
                              }
                          },
                          geteditorvalue: function (row, cellvalue, editor) {
                              // return the editor's value.
                              return editor.val();
                          }
                      },
                     {
                         text: 'Upload', width: 250, columntype: 'custom', datafield: 'upload',
                         cellsrenderer: function (row, column, value) {
                             if (value == "") {
                                 return "Select a file";
                             };
                         },
                         createeditor: function (row, cellvalue, editor, cellText, width, height) {
                             // construct the editor. 
                             editor.html('<input id="fileInput' + row + '" type="file" />');
                         },
                         geteditorvalue: function (row, cellvalue, editor) {
                             // return the editor's value.
                             var value = $("#fileInput" + row).val();
                             return value.substring(value.lastIndexOf("\\") + 1, value.length);
                         }
                     }
                    ]
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id="jqxgrid">
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    In Grid want to add file upload #46560

    sachinhere
    Participant

    How Can i get files after submit? How can i get the data after submit…..

    In Grid want to add file upload #46637

    Dimitar
    Participant

    Hi sachinhere,

    For security reasons you cannot get the file path from a file input via JavaScript code. Instead, the browser gives you a path like this:

    C:\fakepath\file.ext

    The only correct part is the file name and its extension, that is why in our example the geteditorvalue callback function returns only them.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    In Grid want to add file upload #47304

    akshayyes
    Participant

    # I am not able to BIND – rowdata of image in updaterow: / update command. Other remaining data is updated excluding the Image/Photo column.
    # As a result, the name & extension of (file name) photo image is not inserted into mysql database table.

    +++++ CODE BELOW ++++++

    <!DOCTYPE html>
    <html lang=”en”>
    <head>
    <link rel=”stylesheet” href=”../jqwidgets/styles/jqx.base.css” type=”text/css” />
    <link rel=”stylesheet” href=”../jqwidgets/styles/jqx.classic.css” type=”text/css” />
    <script type=”text/javascript” src=”../scripts/jquery-1.10.2.min.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxcore.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxbuttons.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxscrollbar.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxmenu.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxcheckbox.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxlistbox.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxdropdownlist.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxgrid.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxdata.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxgrid.selection.js”></script>
    <script type=”text/javascript” src=”../jqwidgets/jqxgrid.edit.js”></script>
    <script type=”text/javascript”>
    $(document).ready(function () {
    // prepare the data
    var data = {};
    var theme = ‘classic’;
    var source =
    {
    datatype: “json”,
    datafields: [
    { name: ‘id’ },
    { name: ‘brand’ },
    { name: ‘part_no’ },
    { name: ‘size’ },
    { name: ‘resolution’ },
    { name: ‘aspect_ratio’ },
    { name: ‘contrast_ratio’ },
    { name: ‘brightness’ },
    { name: ‘outline_dimension’ },
    { name: ‘production_status’ },
    { name: ‘photo’ }

    ],

    id: ‘id’,
    url: ‘data.php’,
    updaterow: function (rowid, rowdata, commit) {
    // synchronize with the server – send update command
    var data = “update=true&brand=” + rowdata.brand + “&part_no=” + rowdata.part_no + “&size=” + rowdata.size;
    data = data + “&resolution=” + rowdata.resolution + “&aspect_ratio=” + rowdata.aspect_ratio + “&contrast_ratio=” + rowdata.contrast_ratio ;
    data = data + “&brightness=” + rowdata.brightness + “&outline_dimension=” + rowdata.outline_dimension + “&id=” + rowdata.id;
    data = data + “&production_status=” + rowdata.production_status;

    $.ajax({
    dataType: ‘json’,
    url: ‘data.php’,
    data: data,
    success: function (data, status, xhr) {
    // update command is executed.
    commit(true);
    },
    error: function () {
    // cancel changes.
    commit(false);
    }
    });
    }

    };

    // initialize jqxGrid
    $(“#jqxgrid”).jqxGrid(
    {
    width: 1200,
    height: 350,
    selectionmode: ‘singlecell’,
    source: source,
    theme: theme,
    editable: true,
    columns:
    [
    { text: ‘id’, datafield: ‘id’, width: 100 },
    { text: ‘Brand’, columntype: ‘dropdownlist’, datafield: ‘brand’, width: 100 },
    { text: ‘Part No’, columntype: ‘dropdownlist’, datafield: ‘part_no’, width: 100 },
    { text: ‘Size’, datafield: ‘size’, width: 180 },
    { text: ‘Resolution’, datafield: ‘resolution’, width: 180 },
    { text: ‘AspectRatio’, datafield: ‘aspect_ratio’, width: 100 },
    { text: ‘ContrastRatio’, datafield: ‘contrast_ratio’, width: 140 },
    { text: ‘Brightness’, datafield: ‘brightness’, width: 140 },
    { text: ‘OutlineDimension’, datafield: ‘outline_dimension’, width: 140 },
    { text: ‘production_status’, datafield: ‘production_status’, width: 140,columntype: ‘checkbox’},
    {
    text: ‘Upload’, width: 250, columntype: ‘custom’, datafield: ‘photo’,
    cellsrenderer: function (row, column, value) {
    if (value == “”) {
    return “Select a file”;
    };
    },
    createeditor: function (row, cellvalue, editor, cellText, width, height) {
    // construct the editor.
    editor.html(‘<input id=”fileInput’ + row + ‘” type=”file” name=”fileInput” />’);
    },
    geteditorvalue: function (row, cellvalue, editor) {
    // return the editor’s value.
    var value = $(“#fileInput” + row).val();
    //return value.substring(value.lastIndexOf(“\\”) + 1, value.length);
    return value.substring(value.lastIndexOf(“\\”) + 1, value.length);
    }
    }

    ]
    });
    });
    </script>
    </head>
    <body class=’default’>
    <div id=”jqxgrid”>
    </div>
    </body>
    </html>

    In Grid want to add file upload #47310

    akshayyes
    Participant

    +++++++++++++ and this is PHP CODE +++++++++++++++
    <?php
    #Include the connect.php file
    include(‘connect.php’);
    #Connect to the database
    //connection String
    $connect = mysql_connect($hostname, $username, $password)
    or die(‘Could not connect: ‘ . mysql_error());
    //Select The database
    $bool = mysql_select_db($database, $connect);
    if ($bool === False){
    print “can’t find $database”;
    }
    // get data and store in a json array
    $query = “SELECT * FROM beyond_lcdpanel”;
    if (isset($_GET[‘update’]))
    {

    //$target = “../image/” ;
    //$target = $target . basename( $_FILES[‘fileInput’][‘name’]);
    // UPDATE COMMAND
    $update_query = “UPDATE beyond_lcdpanel SET brand='”.$_GET[‘brand’].”‘,
    part_no='”.$_GET[‘part_no’].”‘,
    size='”.$_GET[‘size’].”‘,
    resolution='”.$_GET[‘resolution’].”‘,
    aspect_ratio='”.$_GET[‘aspect_ratio’].”‘,
    contrast_ratio='”.$_GET[‘contrast_ratio’].”‘,
    brightness='”.$_GET[‘brightness’].”‘,
    production_status= ‘”.$_GET[‘production_status’].”‘,
    outline_dimension= ‘”.$_GET[‘outline_dimension’].”‘,
    outline_dimension= ‘”.$_GET[‘outline_dimension’].”‘ WHERE id='”.$_GET[‘id’].”‘”;
    //photo= ‘”.$_GET[‘photo’].”‘ WHERE id='”.$_GET[‘id’].”‘”;
    //photo='”.$_FILES[‘fileInput’][‘name’].”‘ WHERE id='”.$_GET[‘id’].”‘”;
    $result = mysql_query($update_query) or die(“SQL Error 1: ” . mysql_error());
    // move_uploaded_file($_FILES[‘fileInput’][‘tmp_name’], $target);
    echo $result;

    }

    else
    {
    // SELECT COMMAND
    $result = mysql_query($query) or die(“SQL Error 1: ” . mysql_error());
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $beyond[] = array(
    ‘id’=>$row[‘id’],
    ‘brand’ => $row[‘brand’],
    ‘part_no’ =>$row[‘part_no’],
    ‘size’ => $row[‘size’],
    ‘resolution’ => $row[‘resolution’],
    ‘aspect_ratio’ => $row[‘aspect_ratio’],
    ‘contrast_ratio’ => $row[‘contrast_ratio’],
    ‘brightness’ => $row[‘brightness’],
    ‘outline_dimension’ => $row[‘outline_dimension’],
    ‘production_status’ => $row[‘production_status’],
    ‘photo’ => $row[‘photo’]

    );

    }

    echo json_encode($beyond);
    }
    ?>

    In Grid want to add file upload #47312

    Dimitar
    Participant

    Hello akshayyes,

    Your updaterow callback function does not add the photo datafield data to the data variable. Please try the following modified version of it:

    updaterow: function (rowid, rowdata, commit) {
        // synchronize with the server – send update command
        var data = "update=true&brand=" + rowdata.brand + "&part_no=" + rowdata.part_no + "&size=" + rowdata.size;
        data = data + "&resolution=" + rowdata.resolution + "&aspect_ratio=" + rowdata.aspect_ratio + "&contrast_ratio=" + rowdata.contrast_ratio;
        data = data + "&brightness=" + rowdata.brightness + "&outline_dimension=" + rowdata.outline_dimension + "&id=" + rowdata.id;
        data = data + "&production_status=" + rowdata.production_status + "&photo=" + rowdata.photo;
    
        $.ajax({
            dataType: 'json',
            url: 'data.php',
            data: data,
            success: function (data, status, xhr) {
                // update command is executed.
                commit(true);
            },
            error: function () {
                // cancel changes.
                commit(false);
            }
        });
    }

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    In Grid want to add file upload #47314

    akshayyes
    Participant

    Dimitar,
    I have applied your method (suggested by you) but data (File Name) is not updated in my MySQL database table. Please also check the PHP file code I submitted earlier. Waiting for your reply. Thanks.

    In Grid want to add file upload #47315

    akshayyes
    Participant

    Hello Dimitar,
    I have tried to make it work, but it is not done. I have spend several hours in past 2 days. Please get me the code to do the following :-

    Step 1 – Click on Browse Button in JqxGrid
    Step 2 – Pick/Upload the Photo image File (dimitar.jpg)
    Step 3 – Add/Insert the File Name (dimitar.jpg) into mySQL database table

    Waiting for your reply. Thanks.

    In Grid want to add file upload #47317

    Peter Stoev
    Keymaster

    Hi akshayyes,

    As Dimitar pointed out in his post, you do not have code for adding your Photo to your MySQL DB i.e you should update your Ajax call to include the Photo insertion code. As that represents a custom functionality, it should be implemented by you. We can give you only directions, as we already did.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.