npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chunkangwong/grid-query-features

v0.0.14

Published

A React hook library for querying ArcGIS service features from MUI DataGrid v6 with server mode pagination, filtering, and sorting.

Downloads

4

Readme

grid-query-features

A React hook library for querying ArcGIS service features from MUI DataGrid v6 with server mode pagination, filtering, and sorting.

Installation

npm install @chunkangwong/grid-query-features

Basic Usage

import FeatureLayer from "@arcgis/core/layers/FeatureLayer";
import {
  DataGrid,
  GridFilterModel,
  GridInputRowSelectionModel,
  GridPaginationModel,
  GridSortModel,
} from "@mui/x-data-grid"; // MUI DataGrid v6 ONLY
import useGridQueryFeatures from "@chunkangwong/grid-query-features";
import { useState } from "react";

const featureLayer = new FeatureLayer({
  url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
  outFields: ["*"],
});

const App = () => {
  const [paginationModel, setPaginationModel] = useState<GridPaginationModel>({
    page: 0,
    pageSize: 10,
  });
  const [sortModel, setSortModel] = useState<GridSortModel>([]);
  const [filterModel, setFilterModel] = useState<GridFilterModel>();
  const { isLoading, featureSet, objectIds } = useGridQueryFeatures({
    featureLayer,
    paginationModel,
    sortModel,
    filterModel,
  });

  return (
    <DataGrid
      rows={featureSet?.features.map((feature) => feature.attributes) || []}
      rowCount={objectIds?.length || 0}
      getRowId={(row) => row[featureLayer.objectIdField]}
      pagination
      paginationMode="server"
      paginationModel={paginationModel}
      onPaginationModelChange={(newPaginationModel) =>
        setPaginationModel(newPaginationModel)
      }
      sortingMode="server"
      sortModel={sortModel}
      onSortModelChange={(newSortModel) => setSortModel(newSortModel)}
      filterMode="server"
      filterModel={filterModel}
      onFilterModelChange={(newFilterModel) => setFilterModel(newFilterModel)}
      loading={isLoading}
      columns={[
        {
          field: "FID",
          headerName: "FID",
          type: "number",
          width: 150,
        },
        {
          field: "Tree_ID",
          headerName: "Tree_ID",
          type: "number",
          width: 150,
        },
        {
          field: "Status",
          headerName: "Status",
          width: 150,
        },
        {
          field: "Collected",
          headerName: "Collected",
          width: 300,
          type: "date",
          valueFormatter: ({ value }) => {
            return new Date(value).toLocaleDateString();
          },
        },
      ]}
    />
  );
};

API

const { featureSet, objectIds, error, isLoading, refetch } =
  useGridQueryFeatures({
    featureLayer,
    paginationModel,
    sortModel,
    filterModel,
  });

Parameters

Query will be triggered when any of the following parameters change.

  • featureLayer: FeatureLayer

    • Required
    • The feature layer to query features from.
  • paginationModel: GridPaginationModel

    • Required
    • The pagination model from MUI DataGrid. It will be converted to a start and num query props and passed to the feature layer query.
  • sortModel: GridSortModel

    • Required
    • The sort model from MUI DataGrid. It will be converted to a orderByFields query prop and passed to the feature layer query.
  • filterModel: GridFilterModel

    • Optional
    • The filter model from MUI DataGrid. It will be converted to a SQL where clause and passed to the feature layer query.
    • If not provided, "1=1" will be used as the where clause to query all features.
    • Note: For now, Quick Filter is not covered.

Returns

  • featureSet: FeatureSet | null

    • Default to null.
    • The feature set returned from the feature layer query.
  • objectIds: number[] | null

    • Default to null.
    • The object ids returned from the feature layer query. It is used to calculate the total row count for the MUI DataGrid.
  • error: unknown

    • The error returned from the feature layer query.
  • isLoading: boolean

    • Default to false.
    • Whether the feature layer query is loading.
  • refetch: () => Promise<{ objectIds: number[]; featureSet: FeatureSet } | undefined>

    • A function to refetch the feature layer query with the current pagination, sorting, and filtering models. It returns object ids and feature set if the query is successful, otherwise undefined.