jQuery UI Widgets Forums Grid Automated description grid

This topic contains 4 replies, has 2 voices, and was last updated by  Dimitar 10 years, 9 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • Automated description grid #49278

    usrimas
    Participant

    Hi,

    In your samples columns for grid are desribed as arrays with many parameters and functions also .

    Sample of source :
    var columns_for_grid = [
    { datafield: “uzsak” , text: ( $app_lng == ‘lt’ ? “Užsak.ID” : “Order.ID” ), width: 150, editable: true, hidden: false, pinned: true, validation: function( cell, value )
    {
    if ( $.trim( value ).len == 0 )
    return { result: false, message: “Can’t be empty field !” };
    else
    {
    if ( !reqUzsak( value ) )
    return { result: false, message: “Order alreday exist !” };
    }
    return true;
    }
    },
    { datafield: “telkinys” , text: ( $app_lng == ‘lt’ ? “Telkinys” : “Pool” ), width: 80, editable: true, hidden: false },
    { datafield: “uzs_kiekis” , text: ( $app_lng == ‘lt’ ? “Kiekis” : “Qty.” ), width: 75, editable: true , hidden: false, align: ‘right’, cellsalign: ‘right’ },
    { datafield: “svarbus” , text: ( $app_lng == ‘lt’ ? “Svarbus” : “Import.” ), width: 80, editable: true , hidden: false, columntype: ‘checkbox’ },
    { datafield: “specai” , text: ( $app_lng == ‘lt’ ? “Spec.” : “Spec.” ), width: 80, editable: true , hidden: false, columntype: ‘checkbox’ },
    { datafield: “pokav_prad” , text: ( $app_lng == ‘lt’ ? “Pokav.prad.” : “Pack.begin” ), width: 50, editable: false, hidden: false, cellsrenderer: GreenRed }, // columntype: ‘checkbox’,
    { datafield: “prilyg_mod” , text: ( $app_lng == ‘lt’ ? “Prilyg.modelis” : “Equat.model” ), width: 150, editable: true , hidden: false, columntype: ‘combobox’,
    createeditor: function( row, column, editor )
    {
    editor.jqxComboBox( { source: modelSource, promptText: ( $app_lng == “lt” ? “Prašome pasirinkti:” : “Please Choose:” ) } );
    },
    cellvaluechanging: function( row, column, columntype, oldvalue, newvalue )
    {
    if ( newvalue == “”) return oldvalue;
    }
    },

    I want to to improve this proccess through database tables. I have some tables in which I’m storing info about user rights, widths, hidden or not column, column types, formats and captions. Now in 99 % of cases I can describe sources arrays form this datatables . It leaves only this situations where column have own native validations, own functions.

    Can I add this native possibilities after standard parameters ? Let’s say that I created standard description from datatable :

    for ( v in user_grid ) // user rights and sets
    {
    u = findElement( grid_stulp, “grd_fld”, user_grid[ v ].laukas ); // standards sets for table
    if ( u != -1 )
    {
    colums_for_grid[ grd_col ] = { datafield: grid_stulp[ u ].grd_fld, text: ( $app_lng == ‘lt’ ? grid_stulp[ u ].grd_lt : grid_stulp[ u ].grd_en ),
    width: user_grid[ v ].width, editable: user_grid[ v ].edit, hidden: user_grid[ v ].hide }
    grd_col ++;
    }
    }

    After that : $( “#uzs_grd” ).jqxGrid(
    {
    width : wdt,
    height : hgh,
    source : dataAdapter,
    theme : theme,
    columnsresize : true,
    columnsreorder : true,
    filterable : true,
    sortable : true,
    editable : true,
    editmode : ‘dblclick’,
    selectionmode : ‘multiplecellsextended’,
    keyboardnavigation: true,
    columns : columns_for_grid // here goes standard description of columns
    });

    Now after that grid have columns array in which each column is object. But here I can’t fuly understand how to manipulate with column … 🙁 . Let say that I want for data field “uzsak” to do validation ( as in sample above ) . Is this possible ?

    $(‘#uzs_grd’).jqxGrid(‘columns’). ?

    Thanks in advance !

    Automated description grid #49298

    Dimitar
    Participant

    Hello usrimas,

    I understand you wish to dynamically set the grid columns callback functions. Here is an example:

    <!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.selection.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxnumberinput.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                // prepare the data
                var data = new Array();
                var firstNames =
                [
                    "Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene"
                ];
                var lastNames =
                [
                    "Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Bjorn", "Nodier"
                ];
                var productNames =
                [
                    "Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha", "Cramel Latte", "Caffe Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist"
                ];
                var priceValues =
                [
                    "2.25", "1.5", "3.0", "3.3", "4.5", "3.6", "3.8", "2.5", "5.0", "1.75", "3.25", "4.0"
                ];
                for (var i = 0; i < 100; i++) {
                    var row = {};
                    var productindex = Math.floor(Math.random() * productNames.length);
                    var price = parseFloat(priceValues[productindex]);
                    var quantity = 1 + Math.round(Math.random() * 10);
                    row["firstname"] = firstNames[Math.floor(Math.random() * firstNames.length)];
                    row["lastname"] = lastNames[Math.floor(Math.random() * lastNames.length)];
                    row["productname"] = productNames[productindex];
                    row["price"] = price;
                    row["quantity"] = quantity;
                    row["total"] = price * quantity;
                    data[i] = row;
                }
                var source =
                {
                    localdata: data,
                    datatype: "array"
                };
                var dataAdapter = new $.jqx.dataAdapter(source, {
                    loadComplete: function (data) { },
                    loadError: function (xhr, status, error) { }
                });
                $("#jqxgrid").jqxGrid(
                {
                    source: dataAdapter,
                    editable: true,
                    columns: [
                      { text: 'First Name', datafield: 'firstname', width: 100 },
                      { text: 'Last Name', datafield: 'lastname', width: 100 },
                      { text: 'Product', datafield: 'productname', width: 180 },
                      { text: 'Quantity', datafield: 'quantity', width: 80, cellsalign: 'right' },
                      { text: 'Unit Price', datafield: 'price', width: 90, cellsalign: 'right', cellsformat: 'c2', columntype: 'numberinput' },
                      { text: 'Total', datafield: 'total', width: 100, cellsalign: 'right', cellsformat: 'c2' }
                    ]
                });
    
                var columns = $("#jqxgrid").jqxGrid("columns");
                columns.records[4].validation = function (cell, value) {
                    if (value < 0 || value > 15) {
                        return { result: false, message: "Price should be in the 0-15 interval" };
                    }
                    return true;
                };
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left;">
            <div id="jqxgrid">
            </div>
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

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

    Automated description grid #49408

    usrimas
    Participant

    Hi Dimitar,

    Thanks for your help! I did autogeneration of grid.

    var columns = $(“#jqxgrid”).jqxGrid(“columns”);
    columns.records[4].validation = function (cell, value);

    It wasn’t working, but found that must be columns[ colIndex ].validation = ” … It works very fine! Thanks again to you!

    Some other problems – how to filter checkboxs? Form database it come as 1/0 . But filter with this values isn’t working. Also I want to filter “cellsrenderer” with red/green images ( as checkbox , but not editable ) .

    Many thanks in advance ! 🙂

    Automated description grid #49414

    usrimas
    Participant

    Want to add, that directed for checkboxs and mentioned green/red fields filtertype “bool” . But .. this not helped … 🙁

    Automated description grid #49503

    Dimitar
    Participant

    Hello usrimas,

    To filter checkboxes, type in the filter menu either true/false or 1/0 under equal/not equal. Here is an example of a filterable grid with a checkbox column:

    <!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/jqxlistbox.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdropdownlist.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.filter.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.sort.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxgrid.selection.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcalendar.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxdatetimeinput.js"></script>
        <script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>
        <script type="text/javascript" src="../../jqwidgets/globalization/globalize.js"></script>
        <script type="text/javascript" src="../../scripts/demos.js"></script>
        <script type="text/javascript" src="generatedata.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var data = generatedata(500);
                var source =
                {
                    localdata: data,
                    datafields:
                    [
                        { name: 'name', type: 'string' },
                        { name: 'productname', type: 'string' },
                        { name: 'available', type: 'bool' },
                        { name: 'date', type: 'date' },
                        { name: 'quantity', type: 'number' }
                    ],
                    datatype: "array"
                };
    
                var dataAdapter = new $.jqx.dataAdapter(source);
    
                $("#jqxgrid").jqxGrid(
                {
                    width: 685,
                    source: dataAdapter,
                    filterable: true,
                    selectionmode: 'multiplecellsextended',
                    columns: [
                      { text: 'Name', columntype: 'textbox', filtertype: 'textbox', filtercondition: 'starts_with', datafield: 'name', width: 115 },
                      {
                          text: 'Product', filtertype: 'checkedlist', datafield: 'productname', width: 220
                      },
                      { text: 'Available', datafield: 'available', columntype: 'checkbox', filtertype: 'bool', width: 67 },
                      { text: 'Ship Date', datafield: 'date', filtertype: 'date', width: 210, cellsalign: 'right', cellsformat: 'd' },
                      { text: 'Qty.', datafield: 'quantity', filtertype: 'number', cellsalign: 'right' }
                    ]
                });
                $('#clearfilteringbutton').jqxButton({ height: 25 });
                $('#clearfilteringbutton').click(function () {
                    $("#jqxgrid").jqxGrid('clearfilters');
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id="jqxgrid">
        </div>
        <input style="margin-top: 10px;" value="Remove Filter" id="clearfilteringbutton"
            type="button" />
    </body>
    </html>

    And could you, please, provide more information about your cellsrenderer filtering requirement?

    Best Regards,
    Dimitar

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

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.