Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - omerix

Pages: [1] 2 3 ... 11
1
Hello,

I have implemented custom functions to save and load only the column order (order), visibility (hidden), and width (width). Below are my simplified customSaveState and customLoadState functions:

My question is: After setting the new colModel, is calling only grid.refreshCM() (Only:order, width, hidden properties) sufficient to apply these changes? Or should I also call grid.refresh() or another method?

I load this layout in the "create" command like this:
Code: [Select]
        create: function () {
            //this.loadState({ refresh: false })
            customLoadState(this, "isim1");
        },


Code: [Select]
function customSaveState(grid, key) {
    function simplifyColModel(colModel) {
        return colModel.map(col => {
            const simplified = {
                dataIndx: col.dataIndx
            };
            if (col.width != null) simplified.width = col.width;
            if (col.hidden != null) simplified.hidden = col.hidden;
            if (col.colModel) simplified.colModel = simplifyColModel(col.colModel);
            return simplified;
        });
    }

    const simpleState = simplifyColModel(grid.option("colModel"));
const state=JSON.stringify(simpleState);
    localStorage.setItem(key, state);
    console.log("Custom state saved to localStorage under key:", key);
}


function customLoadState(grid, key) {
    const saved = localStorage.getItem(key);
    if (!saved) {
        console.warn("No saved state found for key:", key);
        return;
    }

function reorderAndMerge(savedModel = [], originalModel = []) {
        const originalMap = {};
        originalModel.forEach(orig => {
            originalMap[orig.dataIndx] = orig;
        });

        const handled = new Set();
        const result = [];

        // savedModel
        for (const saved of savedModel) {
            const orig = originalMap[saved.dataIndx];
            if (!orig) continue;

            const merged = { ...orig };

            if (saved.width != null) merged.width = saved.width;
            if (saved.hidden != null) merged.hidden = saved.hidden;

            // nested colModel
            if (saved.colModel && orig.colModel) {
                merged.colModel = reorderAndMerge(saved.colModel, orig.colModel);
            }

            result.push(merged);
            handled.add(saved.dataIndx);
        }

        // savedModel newColumn
        for (const orig of originalModel) {
            if (handled.has(orig.dataIndx)) continue;

            const merged = { ...orig };

            if (orig.colModel) {
                merged.colModel = reorderAndMerge([], orig.colModel);
            }

            result.push(merged);
        }

        return result;
    }


    const savedCols = JSON.parse(localStorage.getItem("isim1") || "[]");
    const currentCols = grid.option("colModel");
    const updated = reorderAndMerge(savedCols, currentCols);
    console.log(currentCols);
    grid.option("colModel", updated);
    grid.refreshCM();
    //grid.refresh();
    console.log("Custom state loaded from localStorage:", key);
}

2
Help for ParamQuery Pro / Re: Using loadState in grouped fields
« on: March 17, 2025, 06:52:16 pm »
Yes, interestingly enough, sometimes the error does not appear in the console.

But if you try this, loadState doesn't seem to work when "colmodel" is used inside "colmodel".

- Drag and drop the "Order Date" column between the "Required Date" and "Shipped Date" columns.
- Then click the saveState button
- When you refresh the page and run the loadState function, you will see that the change has not been saved.

3
Help for ParamQuery Pro / Using loadState in grouped fields
« on: March 10, 2025, 04:10:13 pm »
Hello,

I have a grid where I group some columns using ParamQuery Grid. I grouped the columns in colModel again using colModel.

For example, I created a group called "Dates". Then I moved the column "Order Date" into it. However, when I try to save and restore this change, I get an error.

In some cases, I get the error "p is undefined".



https://jsfiddle.net/5j760ehL/3/
Code: [Select]
    {
      title: "Dates",
      align: "center",
      dataIndx: "grupDates",
      hidden: false,
      colModel: [
        {
          title: "Required Date",
          width: 100,
          dataIndx: "RequiredDate",
          dataType: "date",
        },
        {
          title: "Shipped Date",
          width: 100,
          dataIndx: "ShippedDate",
          dataType: "date",
        },
      ],
    }


Error line: ParamQuery 10.1.0 line 5585
Code: [Select]
m && (v.parentId != m.parentId && (p = s[v.parentId], g = s[m.parentId]) && (p.colModel.splice(p.colModel.indexOf(v), 1), g.colModel.push(v)), this._saveState(m, v, u))


4
Hello friends,

I have a column on the ParamQuery Grid where I make a user selection and I use select here. Since I don't have a chance to know the user ID value when logging in, I store it as id=value and display it as text=label.

I store the ID value in the database but I display the label (text) value on the grid.

Everything works correctly up to this point, but when I export the grid to Excel, dataIndx, that is, value (ID), appears instead of label.

Is the method I am using correct?

Code: [Select]
,{title:'User Select',dataIndx:'user4',dataType:'string',minWidth:24,width: 100,halign:'center',aciklama:'user4_name'
,hidden:false,editable:true,skipExport: true
,editModel:{ saveKey: $.ui.keyCode.ENTER, keyUpDown: false}
,editor:{type:'select',labelIndx:'label',valueIndx:'value',prepend: {'':'' },options: userList}
,render: function (ui) {return ui.rowData['user4_name']}
}

,{title:'User Name',minWidth:24,width:100,dataIndx:'user4_name',dataType:'string'
,hidden:true,editable:false,skipExport: false,exportRender:true
}


Matching formula with label:
Code: [Select]
formulas: [
['user4_name', rd => (userList.find(opt => opt.value == rd.user4) || {}).label || ""]
]


User list:
Code: [Select]
<script>
var userList = [
{"value":1031,"label":"Paramvir Dhindsa"},
{"value":1051,"label":"?merix Turk"},
{"value":1026,"label":"Bill Gates"}
]
</script>



5
I will try with "beforePaste". Thank you.

6
Sample:

7
Help for ParamQuery Pro / Date Format When Pasting Data from Excel to Grid
« on: February 04, 2025, 11:32:07 pm »
Hello,

When I paste data from Excel to the grid, only "yyyy-mm-dd" is accepted as the date format.

Is there a solution other than making datetype="string"?

Options:
Code: [Select]
fmtDate: 'dd/mm/yyyy',
fmtDateEdit: 'dd/mm/yyyy',
fmtDateFilter: 'dd/mm/yyyy'


colModel
Code: [Select]
{
  title: 'Date Column',
  dataIndx: 'date1',
  dataType: 'date',
  halign: 'center',
  desc: 'Process Date',
  hidden: false,
  editable: true,
  format: 'dd/mm/yyyy',
  editor: { type: 'textbox', init: dateU },
  filter: { crules: [{ condition: 'between' }], menuIcon: false }
}


dateU function
Code: [Select]
function dateU(ui) {
  ui.$cell.find("input")
    .datepicker({
      changeMonth: true,
      changeYear: true,
      dateFormat: pq.excelToJui(ui.column.format),
      showAnim: '',
      onSelect: function () {
        this.firstOpen = true;
      },
      beforeShow: function (input, inst) {
        setTimeout(function () {
          $('.ui-datepicker').css('z-index', 999999999999);
        });
      },
      onClose: function () {
        this.focus();
      }
    });
}


function dateB(ui) {
ui.$cell.find("input")
.bootstrapDatepicker({
format: ui.column.format,
})
.on('changeDate', function (e) {
$(this).focus();
$(this).bootstrapDatepicker('hide');
})
}

function date(ui) {
ui.$cell.find("input")
.attr("type", "date")
.on("focus", function () {
this.showPicker?.();
})
.click();
}

8
I solved it by loading different colModel in the backend. Thank you.

9
Hello paramQuery team,

I noticed a think when using freezeCols in ParamQuery Pro Grid. When columns are frozen, the scrollbar starts from the far left. While this is not a critical it does make scrolling a bit difficult since part of the scrollbar remains on the left side.

When a large number of columns are frozen (for example, covering half the screen), the scrollbar is placed at the bottom of the left panel and becomes less accessible.

Is it possible to display the scrollbar only in the right panel? Since the left side remains static when columns are frozen, it is not really necessary to interact with the scrollbar there.

Alternatively, the scrollbar may appear within the grid width; it would only be visible when focused, so I don't think it would distort the layout.

You can test this behavior by adding freezeCols: 10 to the demo below:
https://paramquery.com/pro/demos/infinite

Thanks in advance for any suggestions!

10
Hello,

Now I remember, can I use parameterized saveState and loadState for the need I wrote below?
Quote
It looks like adding a parameter to saveState might help achieve what I need.

For example, I want to save different states for different users like this:

saveState('A'); 
saveState('B');

Then, I want to load the respective state using something like:

loadState('A'); 
loadState('B');

Would it be possible to achieve this while using the same grid (e.g., id='grid_editing'), but loading different states based on the user?



I need to configure different column orders settings for different users in ParamQuery.

So far, I have been using drag-and-drop to adjust the column order and then saving the state using saveState to store the configuration in localStorage.

Is this the correct approach, or is there a better way to handle this?

For example, for User A, I use the following colModel:

Code: [Select]
colModel: [
    {title: "Product ID"},
    {title: "Product Name"},
    {title: "Quantity Per Unit"},
    {title: "Unit Price"}
]



For User B, I save a different configuration where some columns are reordered, and one column is hidden:

Code: [Select]
colModel: [
    {title: "Product Name"},
    {title: "Unit Price"},
    {title: "Quantity Per Unit"},
    {title: "Product ID",hidden:true}
]


Is saveState the right approach to make these user-specific settings permanent or should I use something different?

Actually, the example I wanted is here, but VueJs is used.
https://paramquery.com/pro/demos/vue_switch_data


For example consider colModel like this https://paramquery.com/pro/demos/editing_batch
Code: [Select]
            colModel: [
                { title: "Product ID", dataType: "integer", dataIndx: "ProductID", editable: false, width: 80 },
                {
                    title: "Product Name", width: 165, dataType: "string", dataIndx: "ProductName",
                    validations: [
                        { type: 'minLen', value: 1, msg: "Required" },
                        { type: 'maxLen', value: 40, msg: "length should be <= 40" }
                    ]
                },
                {
                    title: "Quantity Per Unit", width: 140, dataType: "string", align: "right", dataIndx: "QuantityPerUnit",
                    validations: [
                        { type: 'minLen', value: 1, msg: "Required." },
                        { type: 'maxLen', value: 20, msg: "length should be <= 20" }
                    ]
                },
                {
                    title: "Unit Price", width: 100, dataType: "float", dataIndx: "UnitPrice",
                    validations: [{ type: 'gt', value: 0.5, msg: "should be > 0.5" }],
                    render: function (ui) {
                        var cellData = ui.cellData;
                        if (cellData != null) {
                            return "$" + parseFloat(ui.cellData).toFixed(2);
                        }
                        else {
                            return "";
                        }
                    }
                },
                { hidden: true },
                {
                    title: "Units In Stock", width: 100, dataType: "integer", dataIndx: "UnitsInStock",
                    validations: [
                        { type: 'gte', value: 1, msg: "should be >= 1" },
                        { type: 'lte', value: 1000, msg: "should be <= 1000" }
                    ]
                },
                {
                    title: "Discontinued", width: 100, dataType: "bool", align: "center", dataIndx: "Discontinued",
                    editor: false,
                    type: 'checkbox',
                    validations: [{ type: 'nonEmpty', msg: "Required" }]
                },
                {
                    title: "", editable: false, minWidth: 83, sortable: false,
                    render: function (ui) {
                        return "<button type='button' class='delete_btn'>Delete</button>";
                    },
                    postRender: function (ui) {
                        console.log('postRender');
                        var rowIndx = ui.rowIndx,
                            grid = this,
                            $cell = grid.getCell(ui);

                        $cell.find("button").button({ icons: { primary: 'ui-icon-scissors' } })
                        .bind("click", function () {

                            grid.addClass({ rowIndx: ui.rowIndx, cls: 'pq-row-delete' });

                            setTimeout(function () {
                                var ans = window.confirm("Are you sure to delete row No " + (rowIndx + 1) + "?");
                                grid.removeClass({ rowIndx: rowIndx, cls: 'pq-row-delete' });
                                if (ans) {
                                    grid.deleteRow({ rowIndx: rowIndx });
                                }
                            },100)
                        });
                    }
                }
            ],

I want to change the order like this.
Code: [Select]
const userSettings = {
    "A": [
        {title: "Product ID"},
        {title: "Product Name"},
        {title: "Quantity Per Unit"},
        {title: "Unit Price"}
    ],
    "B": [
        {title: "Product Name"},
        {title: "Unit Price"},
        {title: "Quantity Per Unit"},
        {title: "Product ID"}
    ]
};

const userId = "B";  // SET B User

console.log("User B's Column Settings:", userSettings[userId]);

11
I just discovered rowTemplate and managed to use it to set default values ​​for rows added with paste. I even removed the default value assignment from addRow as it was no longer needed.

It seems that rowTemplate does not affect my existing rows because I set the default values ​​to '' or 0 in the dataModel.

I will still take a look at beforeValidate and change things as you suggested. Thanks for the suggestion!

12
Hello,

I can perform various operations when adding rows using the addRow method. However, sometimes I use copy-paste to add multiple rows, and in this case, the addRow method is not triggered.

I tried using the beforePaste event, but it executes for all rows, including the existing ones that are not newly added.

What I need is an event that triggers only when a new row is added to the grid, whether through addRow or paste functionality. Is there something like a beforeRowAdd event or any alternative to achieve this?



This function "GridNew()" assigns default values to new rows.
I use it to add new rows and set default values for them, but it does not work for rows added via paste.

The goal is to make it work for rows added through paste as well.


Code: [Select]
window.GridNew = function () {
 
    function applyDefaultValues(rowData) {
        var defaultValues = { type: 1, code: 'newCode',quantity:1 };
        return Object.assign({}, defaultValues, rowData);
    }

    // Adding a new row
    var newRowData = applyDefaultValues({}); // Apply default values

    if (localStorage.getItem('qpRowBottom') == 1) {
        // Adding a new row at the bottom
        var pm = grid.option("pageModel");
        grid.option("pageModel", { type: 'local', curPage: 1, rPP: pm.rPP, rPPOptions: pm.rPPOptions });
        var rowIndx = grid.addRow({
            newRow: newRowData,
            track: true,
            history: false,
            checkEditable: false,
            refresh: true
        });
        console.log("New row added: Bottom");
        grid.goToPage({ rowIndx: rowIndx });
        grid.editFirstCellInRow({ rowIndx: rowIndx });
    } else {
        // Adding a new row at the top
        var rowIndx = grid.addRow({
            rowIndxPage: 0,
            newRow: newRowData,
            track: true,
            history: false,
            checkEditable: false,
            refresh: true
        });
        console.log("New row added: Top");
        grid.editFirstCellInRow({ rowIndx: rowIndx });
    }


};




Thank you for your help!








13
Hello Paramvir Teams,


This formula functionality is extremely useful for data entry tasks as it saves time and avoids the need for external tools like calculators. It simplifies tasks directly within the grid by allowing quick computations.

I want to achieve Excel-like behavior in the ParamQuery grid during cell editing. Specifically:

I start formula input by typing = in a cell, which puts the cell in edit mode.

*) While still in edit mode, I want to click another cell in the grid and have its reference automatically added to the formula in the editing cell (e.g., =D4).

*) Currently, clicking another cell exits the edit mode. I would like to prevent this behavior so that the cell remains in edit mode, and the clicked cell's reference is inserted into the formula.

*) Is it possible to implement such behavior in ParamQuery? If yes, could you please share an example configuration or code to achieve this?


For example, I attempted to calculate the weight by typing = in the "Freight" column
https://paramquery.com/pro/demos/freeze_columns

Thanks

14
Help for ParamQuery Pro / Re: About using saveState and loadState
« on: January 03, 2025, 06:35:52 pm »
Hello Paramvir,

I updated the JSFiddle: https://jsfiddle.net/omerx/09qagv3z/ ,  but it doesn't work the same way as it does locally.

What I want to achieve: I would like to save all options (like those in the grid_parts demo) to localStorage using saveState and then reload them from there.

The idea is to create something like a merged version of the grid_parts  demo and the grid_state demo.

grid_parts  : https://paramquery.com/pro/demos/grid_parts
grid_state  : https://paramquery.com/pro/demos/grid_state

In addition to saving column layouts, I want to save and load other settings from localStorage. I would also like to include options for pageModel, sortModel, and filterModel. These options should allow users to toggle between local and remote settings, and the grid should restore them from localStorage when revisiting.

I've tried some implementations in JSFiddle but couldn't make it work. Any guidance would be greatly appreciated!

15
Help for ParamQuery Pro / Can I assign properties to numberCell from data?
« on: December 28, 2024, 04:40:02 am »
Hi,

Using pq_cellattr and pq_cellcls I can format columns or display tooltips using titles based on data values.

Can I do it in numberCell?

I tried the following but it didn't work as expected:

Code: [Select]
pq_cellcls: { "recIndx": "green" }
pq_cellcls: { "numberCell": "green" }
pq_cellattr: { numberCell: { title: 'It was recorded without any errors.' } }


Sources
- https://paramquery.com/pro/demos/row_class
- https://paramquery.com/pro/demos/comments


Pages: [1] 2 3 ... 11