<script type="text/javascript">
$(function () {
$("#Grid").ejGrid({
// the datasource "window.gridData" is referred from jsondata.min.js
dataSource: window.gridData,
commonWidth: 120,
allowPaging: true,
toolbarSettings: {showToolbar: true, toolbarItems: [ej.Grid.ToolBarItems.Search] },
columns: [
{ field: "OrderID", headerText: "Order ID", isPrimaryKey: true, textAlign: ej.TextAlign.Right, width: 75 },
{ field: "CustomerID", visible:false, headerText: "Customer ID" },
--------------------
],
load: "searchingColumn"
});
});
function searchingColumn(args) {
var columns = args.model.columns;
for (var i = 0; i < columns.length ; i++) {
if (columns[i].visible == true || ej.isNullOrUndefined(columns[i].visible)) {
args.model.searchSettings.fields.push(columns[i].field); // pus the field names which shown in Grid based on visible property
}
}
}
</script>
|
Hi again.
I forgot to tell you that my search input is out of the grid, as you can see in the next picture.
How can I search only in visible columns?
I will be awating for your reply, thanks in advance.
Kind regards, Luis.
</body>
<div class="content-container-fluid">
<div class="row">
<input type="text" id="serachval" name="serachval" />
<button id="Searching"> Clickme </button>
----------
</div>
<script type="text/javascript">
$(function () {
$("#Grid").ejGrid({
----------
allowSearching: true,
columns: [
{ field: "CustomerID",visible:false, headerText: "Customer ID" },
----------------
],
load: "searchingColumn"
});
$("#Searching").ejButton({size: "small", click: "onSearching" });
});
function searchingColumn(args) {
var columns = args.model.columns;
for (var i = 0; i < columns.length ; i++) {
if (columns[i].visible == true || ej.isNullOrUndefined(columns[i].visible)) {
args.model.searchSettings.fields.push(columns[i].field);
}
}
}
function onSearching(args){
var gridObj = $("#Grid").ejGrid("instance");
var val = $("#serachval").val();
gridObj.search(val);
}
</script>
|
Thanks!! it works perfectly!
Hi again.
I've recently found a mistake with this function.
The first image shows four columns, three of them are date types. The data source of these columns are numerics (ex: 980809200000) and the function called "queryCellInfo" turns these numbers into dates with format "DD/MM/YYYY" (ex: 30/01/2001).
As far as I concern, when I look for the string "2017" it shouldn't compare to data source, it ought to compare to data showed in website.
As you can see in the image 2 and 3 it compares to data source, so, how can I compare to data showed in website?
IMAGE 1
IMAGE 2
IMAGE 3
I will be awating for your reply, thanks again.
Regards, Luis.
$(function () {
var Data = [
{ OrderID: 10248, CustomerID: 'VINET', EmployeeID: 1, Freight: 33.38,ShipName:'Alfreds Futterkiste',ShipCountry:'1',OrderDate:180895500022},
---
];
$("#Grid").ejGrid({
// the datasource "window.gridData" is referred from jsondata.min.js
dataSource: Data,
commonWidth: 120,
allowPaging: true,
allowSearching: true,
columns: [
---
{field:"OrderDate", headerText:"Order Date",
format:"{0: dd/MM/yyyy}", width:90}
],
load: " searchingColumn"
});
});
function searchingColumn(args) {
for(var j=0 ; j< args.model.dataSource.length; j++){
args.model.dataSource[j].OrderDate = new Date(args.model.dataSource[j].OrderDate);
}
}
|
Hi again.
Maybe I didn't explain well, let me try again, please.
As you can see in the next image, the "queryCellInfo" function shows the employee's name instead of employee's id. However, I'd like to save the employee's id and to search for the employee's name.
I modified your example in order to let you know my problem.
http://jsplayground.syncfusion.com/eus3kl3o
I will be awating fot your reply, thanks again.
Regards, Luis.
<script type="text/javascript">
var fdata = [{ EmployeeID: 1, FirstName: "Nancy" },
---
];
var Data = [
{ OrderID: 10248, CustomerID: 'VINET', EmployeeID: 1, Freight: 33.38, ShipName: 'Alfreds Futterkiste', ShipCountry: '1', OrderDate: 180895500022 },
---
];
$(function () {
$("#Grid").ejGrid({
// the datasource "window.gridData" is referred from jsondata.min.js
dataSource: Data,
---
columns: [
{ field: "FirstName", headerText: "Employee ID", textAlign: ej.TextAlign.Right, width: 100 },
---
],
load: "searchingColumn"
});
});
function searchingColumn(args) {
this.model.dataSource.adaptor = new ej.ForeignKeyAdaptor([
{ foreignKeyField: "EmployeeID", foreignKeyValue: "FirstName", dataSource: fdata }], "JsonAdaptor");
----
}
---
</script>
|
Hi again.
Could you apply this solution for two columns?
For instance, I would like to apply this solution for "OrderID" and "EmployeeID" columns. Here you have the array to the "OrderID" column.
var fdata = [{OrderID:10248,OrderName:"First"},
{OrderID:10248,OrderName:"Second"},
{OrderID:10248,OrderName:"Third"},
{OrderID:10248,OrderName:"Fourth"}
];
I will be awaiting for your reply, thanks in advance.
Regards, Luis.
Hi again.
Thank you for your reply, but I can't change the attribute's value called "field" in the "columns" array.
Is there another option?
Regards, Luis.
Hi again.
Is there another way without "ej.ForeignKeyAdaptor" ?
Thank you again.
Regards, Luis.