Clear jqgrid toolbar when custom defaultvalue is set - jqgrid

I want to clear the toolbar of my grid, but not to the default value of the column. I want to empty all fields.
When I use the
$("#Jqgrid")[0].clearToolbar();
method the toolbar gets the initial default values..

You can choose one from the following two ways.
1) You can temporary change the defaultValue of the searchoptions to "" before call of clearToolbar. You can use setColProp method for example to change column properties (see en example here).
2) Set the value of the the toolbar element manually to "" or to any other value which you want. There are simple way how the ids of the input or select elements of the toolbar are constructed. Let us you have column with the name 'col1' (the corresponding column of colModel has name: 'col1'). Then the id of the element in the filter toolbar will be gs_col1. So you can use
$("#gs_col1").val("");
to clear the field. In more general case if the colname is the variable which hold the value from colModel[i].name you can use
$("#gs_" + $.jgrid.jqID(colname)).val("");

Related

Setting date value in an Interactive grid based on a page item

I am trying to set a interactive grid column value (which is a date) based on a page item (which is also a date). I have already tried defaulting and using dynamic action set value (jquery seletor) to set item value to the interactive grid column but it does not work how I want it to work.
I have a page item called "P_DEF_DATE" and I want to set a date column in the interactive grid to this value but I want when I change the value in the page item and I click add row on the interactive grid, it must always use whatever value I have in the page item. For example:
P_DEF_DATE = 12-JAN-2021
when I click on add row in the interactive grid, my date column must equal to P_DEF_DATE and i add a few rows based on that date but then i change the date of P_DEF_DATE to:
P_DEF_DATE = 28-JAN-2021
now I want when I click on add row in the interactive grid, I it must show this new date from the page item in the date column in the interactive grid, keeping in mind the page does not refresh and I have rows with the date 12-JAN-2021.
Thank you in advance!
I implemented same few days ago. Following is what I did.
Create Dynamic Action on Row Initialization Event, set Region to your IG
Set True Action to Execute JavaScript Code
Use code
var model = this.data.model,
rec = this.data.record,
meta = model.getRecordMetadata(this.data.recordId);
if ( meta.inserted ) {
model.setValue(rec,"COLUMN_NAME", $v("P_DEF_DATE"));
}
Replace JOB with your column name and P_DEF_DATE with you Item name
More details Here
Also, out of curiosity, why there is no number like P1, P2 in your item name ??

Tableau: How to restrict a dropdown filter to fields that start with "2021*" (a fiscal week field that adds a new field weekly)?

I need an automatic way to have new fiscal weeks (a string that looks like yyyyww) added to my dropdown filter. It's necessary that it's a dropdown unfortunately. Can I just filter out all values that don't start with "2021*" in this particular table? I use those other values in other parts of my dashboard, so I can't filter them out of my data completely.
Create a calculation called DateDisplay as follows:
IF STARTSWITH((STR([Period])),'2021') = TRUE then 'Display'
END
Add the new DateDisplay field to the Filters Shelf and uncheck NULL
Select 'Show Filter' for the string date field
On the drop down menu (down arrow on the right) for the filter which is now showing, select the options 'Only Relevant Values'

In Free JQGrid how can i add a input field in column header

I have a requirement to add a input field in column header, the requirement is, upon checking some checkbox's(rows) of jqgrid user can simply type text value in a input field in column header which will be automatically populated to all its cell values below this column. Basically this will eliminate user's effort of entering values in each cell of that column.
Example: if i enter VICTE in column header then all the below cell values of that column should be auto populated with that VICTE value.
So how can i add a input field in column header ?
In colNames array you can put any valid html content including input fields. After that it is easy to bind any event you want knowing the id of the input fields. By example you can write
$("#grid").jqGrid({
...
colNames : ['ShipName',...,'<input id="id1" type="text">',...]
...
});

Hide an element conditionally by its value

I have a kendo grid containing following columns.
1.Name
2.Age
3.Type{values:public,private}
I need to hide a column in specific row. In my problem, i want to hide age cell if Type value is private.
using if else format
columns.Template(#<text></text>)
.ClientTemplate("#if (field == value) {#"
+ "<a></a>"
+ "#}else {#"
+"<input name='chkSubscribed' class='subscribedClass'type='type': '' #/>"
+ "#} #").Width(130).Title("title");
You can't hide the cell but you can hide the age depending of the other columns. See https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-apply-conditional-logic-to-client-column-templates on how to apply conditional logic to columns?

MVC3 Set Drop down list Selected value

#Html.DropDownListFor(m => m.field, Model.fieldList, "Select")
I have the code above to get the values of a drop down list from a database. Because the database does not have the select value, I am add it to the list. However, I want to set the selected value to a certain value(variable). How can I do this?
Say I want the selected value to be "WI" and "WI" is in the list. How do i do this? Or how do I specify the #value property?
The DropDownListFor function will first look if there is a selected value in the provided select list. If there are no selected values in the selected list items, it will look at the value of the field that the drop down list is for and attempt to match that to the value of each select list item until it finds the correct one. If any select list item does not have value, it will compare it to the text instead.
Once you have the full list generated, loop through it and find the value you want selected, then set the selected property to true and it should choose that one.

Resources